0

located at File System -> tmp/crontab.iRppRO I've got this

1 * * * * /bin/bash ./usr/share/cacti/cli/cacti_moto_script.sh

and here's my script, which works fine when I run in terminal. It's located at /usr/share/cacti/cli/cacti_moto_script.sh

and here's the script.

 #!/bin/bash
php -q add_device.php --description="x.x.x.x" --ip="x.x.x.x" --template=29 --community="Canopy"
php -q add_device.php --description="x.x.x.x" --ip="x.x.x.x" --template=29 --community="Canopy"
php -q add_device.php --description="x.x.x.x" --ip="x.x.x.x" --template=29 --community="Canopy"
php -q add_device.php --description="x.x.x.x" --ip="x.x.x.x" --template=29 --community="Canopy"
php -q add_device.php --description="x.x.x.x" --ip="x.x.x.x" --template=29 --community="Canopy"
php -q add_device.php --description="x.x.x.x" --ip="x.x.x.x" --template=29 --community="Canopy"

I know I've got the crontab scheduled for every 1 minute (just trying to get it to work first) but I'd like it to be once every hour.

GarrettVW
  • 11
  • 2

1 Answers1

0

Check your environment variables.

Cron jobs do not inherit your shell's environment variables. They typically get only a few variable settings, such as $HOME, $PATH (typically just /usr/bin:/bin), $SHELL, $PWD, and a few others.

Whatever environment variables your script needs will have to be set explicitly. You can do this in your crontab itself, or you can update your script so it sets them (the latter is probably the better approach).

Incidentally, the crontab in the question:

1 * * * * /bin/bash ./usr/share/cacti/cli/cacti_moto_script.sh

will (attempt to) run the command once per hour, at one minute after the hour. To run it once per minute, use * * * * *.

And assuming your script starts with #!/bin/bash (which must be at the very start of the first line), and it has execute permission (chmod +x), you don't need to invoke /bin/bash explicitly. You can just execute the script directly. (That's what the #! line is for, after all.)

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • Specifically which environment variables does my script need to have set? – GarrettVW Mar 19 '14 at 18:46
  • @GarrettVW: That depends on your script. You'll need to look at the environment in your interactive shell and figure out which variables are needed. It's impossible to tell without knowing what `add_device.php` does. – Keith Thompson Mar 20 '14 at 16:28