Saturday, January 27, 2024

[SOLVED] Cron script not executing at correct time

Issue

I'm running Ubuntu 22.04 and am trying to execute a script each morning at 06:30am.

Using sudo crontab -e I've placed the following two lines

@reboot /home/ubuntu/download.sh
30 6 * * * /home/ubuntu/download.sh

I've also ensured that the download.sh script is executable with sudo chmod +x download.sh. The file returns green when I do an ls in that directory, indicating it's executable, I believe.

Here's the thing:

  1. download.sh can be executed successfully with ./download.sh
  2. @reboot is working
  3. 30 6 * * * /home/ubuntu/download.sh does not work

I've also tried 30 6 * * * /usr/bin/sh /home/ubuntu/download.sh, without success.

I've got the timezone set to my local, and using date confirms this, so I'm confident it should be executing at the right time compared to the time on my local clock.

So... Any thoughts are much appreciated


Solution

Th cron script needed to have precisely one blank line at the end. No spaces, no nothing. Just a single blank line.



Answered By - anakaine
Answer Checked By - Mildred Charles (WPSolving Admin)