Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in crontab entry

Tags:

cron

I have been trying to make a cron entry for a shell script:

50 */4 * * * /path/script-file.sh > /dev/null 2>&1

aimed to run the script at HH:50 at a frequency of 4 hours. But this errors out with the message:

crontab: error on previous line; unexpected character found in line.

crontab: errors detected in input, no crontab file generated.

I removed the "/4" and the error vanished, but I know that cron does allow this format. Does anybody know what the issue could be?

Thank you very much for any help.

like image 680
Abhilash Avatar asked Feb 26 '26 11:02

Abhilash


1 Answers

Some cron implementations don't support steps (e.g. */4) - check man 5 crontab on your particular system.

You can use the list 0,4,8,12,16,20 instead.

Off-topic: If you are using bash, you could probably replace > /dev/null 2>&1 with the shorter &>/dev/null or just close stdout and stderr with 1>&- 2>&-. (see @Keith Thompson's comment below)

like image 125
Radko Dinev Avatar answered Mar 03 '26 03:03

Radko Dinev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!