On my server I am getting the following error when running one of my cron tasks:
CRON[9913]: (CRON) error (grandchild #9915 failed with exit status 127)
The server is running Ubuntu-1104-natty-64-minimal.
I am using the Whenever gem along with the Backup gem, although the cron task that is failing is only using the Whenever gem to write the crontab file.
The cron task script (for Whenever) is as follows:
set :output, "#{path}/log/cron.log"
every 2.minutes do
command "cd /var/www/outofhours && /usr/local/bin/rake fetch_incomingcalls RAILS_ENV=production"
end
every 1.day, :at => '11:05am' do
command "cd ~/ && ./import_premvet.sh"
end
In the above script, the first script (every 2.minutes do) works perfectly. However, the second (every 1.day) script fails with the error.
The script that it should be running is:
#!/bin/sh
# Untar premvet_sync database and dump into local mysql server.
echo "Finding latest backup directory"
dir=$(ls -td1 /root/backups/premvet_sync/* | head -1)
echo "Opening latest backup directory"
cd $dir
echo "Latest: $dir"
echo "Uncompress premvet_sync.tar"
tar -xvf premvet_sync.tar
echo "Dig down into correct directory"
cd $dir/premvet_sync/databases/MySQL
echo "mysqldump the compressed database file"
gunzip < premvet.sql.gz | mysql -u root -pPASSWORD premvet
echo "Done."
The permission of the above script are set to:
-rwxrwxrwx 1 root root 510 2012-07-23 11:31 import_premvet.sh
I have also tried changing the above script's first line to:
#!/usr/local/bin/sh
When configuring the Whenever and Backup gem originally I ran the following command to get them working correctly:
sudo ln -s /usr/local/bin/ruby /usr/bin/.
It's important to note that when running the script directly when logged in as root it succeeds.
Cron Log
This is how the task appears in my crontab -e view:
2 13 * * * /bin/bash -l -c 'cd ~/ && ./import_premvet.sh &>/tmp/cronjob.log >> /var/www/outofhours/log/cron.log 2>&1'
When running tail -f /tmp/cronjob.log I get:
tail: cannot open `/tmp/cronjob.log' for reading: No such file or directory
The contents of #{path}/log/cron.log is:
Scraping Calls
Which is a success message from the first cron task. No mention of the second (failing) task/script.
Any help would be appreciated!