1

I want to run a script every day at 10:25 (exact hour is not important) on my Raspberry Pi (running Raspbian Jessie).

With that line : 25 10 * * * /home/pi/test.sh it gave no results, no output and no activity log.

I tried with * * * * * /home/pi/test.sh and there magic happens ! It worked fine, producing CMD (/home/pi/test.sh) in the cron logs, and creating the desired output file.

The script I used for test purposes:

#!/bin/bash
echo `date` > /home/pi/test.txt

Does someone has any idea on why cron doesn't run the script ?

  • You have a probable copy/paste typo of a backtick at the end of the script. Also simpler: date > ...test.txt – Jeff Schaller Feb 14 '17 at 13:19
  • Did you check the time zone on your Raspberry Pi? Does running just date on the command line return the time you expect? – dhag Feb 14 '17 at 14:18
  • @dhag date gave me the time I expected, but it seems (see comments to answer below) that cron is using UTC time, no matter which timezone is set on the RPi. – Jerry Magnin Feb 14 '17 at 14:25
-1

From the crontab manpage

Commands are executed by cron(8) when the minute, hour, and month of year fields match the current time, and at least one of the two day fields (day of month, or day of week) match the current time

You are required to have one of the day fields. If you want this to run at 10:25 every day, just use

25 10 * * 0-6 /home/pi/test.sh

EDIT: This is actually incorrect because all * mark the crontab as executing every minute. We figured out it was system time issue. Double-check your system time. The cron daemon operates off of UTC. Since the script worked when you set all the fields to *, we know the actual logic is working.

|improve this answer|||||
  • 2
    If so, how come @hourly is listed as an alias for 0 0 * * *? – Kusalananda Feb 14 '17 at 12:51
  • I tried your solution, but without success. – Jerry Magnin Feb 14 '17 at 12:53
  • I'm not sure. I've seen other examples where just having the time works too, not sure why in this case OP's solution isn't working. I'm still looking into it. – Patrick Feb 14 '17 at 12:54
  • @JerryMagnin What are you using to edit the crontab? crontab -e? And by that, I mean are you editing your pi user's crontab or the system crontab at /etc/crontab – Patrick Feb 14 '17 at 12:55
  • 2
    Huh? "at least one of the two day fields [...] match the current time" means that a star in those fields will always match, unless the asker is using a seriously weird version of cron. – dhag Feb 14 '17 at 14:20
0

To simplify I would have the job listed as:

25 10 * * * date > /home/pi/test.txt

This will run at 10:25am. If it doesn't run at this time check the timezone in /etc/default/cron and change it if needed. After the change you will want to restart the service service cron restart.

|improve this answer|||||

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.