1

I have been trying to create a cron job to execute a script located in ~/Documents/script.sh at midnight every night and every 8 hours after that.

I have found a lot of material on this but for some it doesn't work.

This is what I have:

* 0 * * * ~/Documents/script.sh
0 */8 * * * ~/Documents/script.sh

closed as unclear what you're asking by Ulrich Schwarz, jimmij, jasonwryan, Braiam, slm Nov 3 '14 at 11:51

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Please show what you've done, starting with the output of crontab -l – Ulrich Schwarz Nov 3 '14 at 7:12
  • @UlrichSchwarz Thanks, I have included what I have so far. Cannot figure out what is the issue. – SSF Nov 3 '14 at 7:20
  • by the way this is one of the sources I used:stackoverflow.com/questions/11562804/… – SSF Nov 3 '14 at 7:22
  • Before analysing the script, please check /var/log/cron and see whether the cron is even trying to run the script. If you use environment variables in the script, it script may give errors while run from cron. – Sree Nov 3 '14 at 7:39
  • Try putting the full path to the scripts in crontab entries, not ~. – slm Nov 3 '14 at 11:51
1

There is no tilde expansion in your cron job, you have to put in something like:

0 */8 * * * /home/yourloginname/Documents/script.sh

This will run script.sh (assuming it is executable (chmod +x script.sh)), at midnight, 8 AM and 4 PM.

Leave out the first line you indicated, that would run the script every minute between midnight and 1 AM.

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