1

I'm writing a script that installs and configures Nagios to my requirements. It requires cpanm and some perl modules.

It's using the step/try/next function from here: https://stackoverflow.com/a/5196220

step "Downloading cpanm installer"
 try `wget -q http://cpanmin.us -O $swrepo/cpanm.install`
next

step "Installing cpanm"
  try echo '{ exec </dev/tty; cat $swrepo/cpanm.install | perl - App::cpanminus; }' | bash
  # try bash -c "$(cat $swrepo/cpanm.install | perl - App::cpanminus)"
  # try cat $swrepo/cpanm.install | perl - App::cpanminus
next

step "Installing Perl module Nagios Config"
  try `cpanm Nagios::Config`
next

My problems here are:

  1. whichever way I attempt to run the install for cpanminus, it fails the script, and won't install properly. I can't seem to make it function outside of the step/try/next functions (not that I want it to.)

  2. The cpanm command fails too. If I isolate and run only this part of the script, it still fails, with "cpanm command not found." I can run it manually at the command line.

Any pointers for the slightly frustrated?

Update

I pulled the cpanm setup out to a separate file: step "Installing cpanm" try sh conf_cpanm.sh next

Which works, and I'll probably try and pull it back in at a later date, but so far that functions. So it can stay.

However, doing the same for try cpanm Nagios::Config won't work. The file looks like this:

#!/bin/bash
cpanm Nagios::Config

...and if I run that by calling sh conf_nagcpanm.sh it works fine.

Community
  • 1
  • 1
andys
  • 11
  • 4

1 Answers1

1

I think using backticks

try `cpanm Nagios::Config`

is a mistake. bash will take an expression in backticks, execute it, and substitute the output of the command for the expression. The output of cpanm is not going to be shell commands, so this will not work. It should simply be

try cpanm Nagios::Config
ikegami
  • 367,544
  • 15
  • 269
  • 518
mob
  • 117,087
  • 18
  • 149
  • 283
  • The install of cpanm won't work either, but to address this, without backticks, the script doesn't even try and run that command, and doesn't push any output to the log file. If i try to put in $(cpanm Nagios::Config) I get "cpanm: command not found". And to test this, I installed cpanm manualy. – andys Jul 10 '15 at 14:19