This question already has an answer here:
I apologize already for asking another cron question. I read dozens of help articles online with still no solution. So for my curiosity, I need to find a solution.
I simply want to run a command every day at 4am. This is what I have done so far:
# crontab -e. Add this line:
00 04 * * * root ruby /home/script.rb list >> /tmp/output.log. (script.rb just contains "puts 'hello'")
- script.rb is owned by root and permissions are set to execute on all users.
- I ran
rvm cron setupto install some environment variables to the crontab file for the cron job to find my ruby executable files.
- Added more environment variables to crontab file such as my
After 4am, I check the cron logs and indeed, the script was executed.
Dec 14 4:00:01 admin CRON: (root) CMD (root ruby /home/script.rb list >> /tmp/output.log) but when I check
/tmp, no output.log file exists. When I run the command by itself, /tmp/output.log shows up and contains hello so the command works.
- So I go back to my crontab file and change
which ruby) to make everything absolute paths. It runs, but still no /tmp/output.log.
- I replace the line in crontab to:
00 04 * * * root /home/run_scriptinstead where
#!/bin/bash /usr/local/rvm/rubies/ruby-2.2.1/bin/ruby /home/script.rb list >> /tmp/output.logto simply try using a script file instead of one line command in crontab. It runs, but still no /tmp/output.log.
- I go into
run_scriptfile and get rid of all the ruby stuff and go the simple route:
#!/bin/bash echo "hello" >> /tmp/output.logIt runs, but still no /tmp/output.log.
I should also note, I set
MAILTO=root in my crontab file, but no mail delivered to root.
- Now I did another experiment, when I take
run_scriptand put it into
/etc/cron.daily, it runs great. No problems.
Other notes: Cron is running:
ps -ef | grep cron | grep -v grep outputs cron is running. There is a blank line after my command in the crontab file.
cron seems pretty tough to debug. The sys log just tells me that the cron job ran but tells nothing else. I am not getting any mail delivered so that cannot help me. Luckily /etc/cron.daily works for now, but I want to know why crontab is not working.
Any suggestions, ideas, hints at debugging?