I opened my crontab file with crontab -e. Then I added this to my crontab:
SHELL=/bin/bash
@hourly /home/ec2-user/utilities/create-snapshots.sh
Then I saved the file. After about an hour, the cron logs displayed:
CROND[1876]: (ec2-user) CMD (/home/ec2-user/utilities/create-snapshots.sh)
CROND[1877]: (root) CMD (/usr/lib64/sa/sa1 -S DISK 1 1)
CROND[1892]: (root) CMD (run-parts /etc/cron.hourly)
run-parts(/etc/cron.hourly)[1892]: starting 0anacron
run-parts(/etc/cron.hourly)[1901]: finished 0anacron
However I know that the command /home/ec2-user/utilities/create-snapshots.sh was not actually run because it would have created snapshots of my database, which it did not. Running the command /home/ec2-user/utilities/create-snapshots.sh works if I run it directly in the terminal.
How can I get cron to run that command hourly?
My psychic debugging powers tell me that the
create-shapshots.shscript was run, but it failed because of an environment variable problem (possiblyPATH). Cron normally runs commands with a cleaned-out environment, with much less stuff than what you normally have at a shell prompt.