0

I have an 'R' script that I wish to run at 00:30 every day, that is, 12:30 AM everyday. The script itself is located in ~/Desktop/foldername/runme.r and which Rscript tells me that the exact path to binary Rscript is /usr/bin/Rscript. So I make the following crontab entry:

crontab -e
54 13 * * * /usr/bin/Rscript ~/Desktop/foldername/runme.r

Time right now is 13:52 of course. And I wait 5 minutes to see if a CSV file is created in my home folder. Since the R script runme.r has instructions to process some data and then create a CSV file in the home folder.

But no luck. At 13:54, no CSV file is created in my home folder. Please note that when I manually run this script (without using cron), it does create a CSV in my home folder. So I know there's nothing wrong with my script. So why is the cronjob not running as intended and what can I do to correct it or how do I check log files for additional sources of information?

EDIT: NEW OBSERVATION

If I change the line to * * * * * /usr/bin/Rscript /home/username/Desktop/foldername/runme.r instead of specifying the exact time, it does create the right CSV file in the right location. So * * * * * works and 54 13 * * * doesn't. Why?

  • 1
    try to use absolute path instead of ~ – Ipor Sircer Aug 25 '16 at 18:02
  • That's what I just thought of as well, and so I tried absolute paths everywhere, even in my R script and cronjob: /home/username/Desktop/... but that didn't work either. I wonder if I have to restart cron process or reboot or something? – learnerX Aug 25 '16 at 18:05
  • I'd start with something simple to test that cron is working for you at all. Something like /usr/bin/touch /tmp/crontest as your command. That will at least let you know that cron is doing the right thing and the problem is with getting it run your Rscript. – Ciclamino Aug 25 '16 at 19:20
  • Is crond running? What happens if you comment that line out and configure "* * * * * /bin/date >> /tmp/test.me" instead – davidgo Aug 25 '16 at 19:23
  • @davidgo crond is running according to ps -e | grep cron. I even restarted it using service crond restart. But no good. Addtionally, I added that test.me line to 'crontab -e' and I can see the test.me file in the tmp folder ! So cron is running fine – learnerX Aug 25 '16 at 19:31
2

I figured it out after the last observation I made regarding time. This is going to make me look silly, but I had gotten the time wrong. I'm testing this cronjob in a virtual machine that has a time different from my host machine. I was scheduling the job in the virtual machine, and looking at the time on my host machine. Both times being different meant that script didn't execute on the time I expected it too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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