How to set CRON job to force reboot at a specified time?

Cron job is not working at all. I have altered the time numerous times, waited for clock to catch up, and job has not executed.

Here’s what I have now:

linux:/etc/cron.d # l
total 24
drwxr-xr-x   2 root root  4096 Nov 19 19:12 ./
drwxr-xr-x 173 root root 12288 Nov 19 17:27 ../
-rw-r--r--   1 root root   542 Oct 11 13:30 mdadm
-rw-r--r--   1 root root    49 Nov 19 18:50 zz-reboot

linux:/etc/cron.d # cat zz-reboot 
52 18 * * * root  /home/gost/MY_CRON_JOBS/reboot

linux:/home/gost/MY_CRON_JOBS # l
total 12
drwxr-xr-x   2 gost users 4096 Nov 19 18:10 ./
drwxr-xr-x 127 gost users 4096 Nov 19 18:20 ../
-rw-r-xr-x   1 root root    20 Nov 19 18:10 reboot*

linux:/home/gost/MY_CRON_JOBS # cat reboot 
#!/bin/bash
reboot

I want to force a reboot at the specified time.

I discovered the problem.

The cron system requires a newline at the end of EVERY line in the crontab file.

This means that when editing a crontab, one must press ENTER at the end of the command. Cron will not process a file missing this required newline.

However, it still will not run from /etc/cron.d. No crontab placed there runs.

When I add it via crontab -e for the user, the cron job runs.

I cannot figure this issue out.

Why not edit /etc/cron.d/zz-reboot to:


52 18 * * * root systemctl reboot 

?

I think cron is designed to respond only to cron -e. It’s a security measure. Read the “man crontab”. Clues in there.

There is no “cron -e” check “man cron” :slight_smile: , which also explains the use of “/etc/cron.d/” etc. “crontab -e” is for normal users to edit their own crontab files in “/var/spool/cron/tabs/”. The files in “/etc/cron.d/”, “/etc/cron.daily/”, “/etc/cron.weekly” and “/etc/cron.monthly” can be edited without a special tool by administrators and can run as any user.