-4

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:

  1. # crontab -e. Add this line: 00 04 * * * root ruby /home/script.rb list >> /tmp/output.log. (script.rb just contains "puts 'hello'")
  2. script.rb is owned by root and permissions are set to execute on all users.
  3. I ran rvm cron setup to install some environment variables to the crontab file for the cron job to find my ruby executable files.
  4. Added more environment variables to crontab file such as my PATH, SHELL=/bin/bash and BASH_ENV=/root/.bashrc.

After 4am, I check the cron logs and indeed, the script was executed. Dec 14 4:00:01 admin CRON[25374]: (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.

  1. So I go back to my crontab file and change ruby to /usr/local/rvm/rubies/ruby-2.2.1/bin/ruby (output of which ruby) to make everything absolute paths. It runs, but still no /tmp/output.log.
  2. I replace the line in crontab to: 00 04 * * * root /home/run_script instead where run_script contains:
    #!/bin/bash /usr/local/rvm/rubies/ruby-2.2.1/bin/ruby /home/script.rb list >> /tmp/output.log to simply try using a script file instead of one line command in crontab. It runs, but still no /tmp/output.log.
  3. I go into run_script file and get rid of all the ruby stuff and go the simple route:
    #!/bin/bash echo "hello" >> /tmp/output.log It 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.

  1. Now I did another experiment, when I take run_script and 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?

marked as duplicate by MadHatter, user9517, Tim Brigham, Wesley, Jenny D Dec 15 '15 at 9:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Yeah, I followed that post. Tried everything it said, no luck. – levibostian Dec 14 '15 at 23:43
  • 2
    @levibostian you must have missed something. The solution to your problem (as stated) is in that post. – user9517 Dec 15 '15 at 7:48
1

That's the wrong format for a user's crontab file. You need to remove the user specification root'. You would have that in/etc/crontab' but not a per-user crontab.

  • 5
    This is already mention in the duplicate that the OP has been directed to, – user9517 Dec 15 '15 at 7:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.