0

i want run a CronJob for reboot the server once or twice at month. I do:

crontab -e

than:

51 9 5 * * /usr/sbin/reboot

This should reboot at 5 day of the month at 9:51, it works the server is reboot but after 30 seconds the reboot continue generating an infinite loop.

Why this happen and how to fix? The only way i have to stop this is remove the CronJob so I'm unable to set an automated reboot once a month.

Any help will be appreciated.

Update 1: The issue is not caused by the too short time of the cron, even if i add +5 minutes or delay the reboot still happen in loop.

1

I'm assuming it is due to a too fast reboot, i.e. the time is still 9:51 when the cron daemon comes up again, so the job is triggered.

One way to work around this would be to delay the actual reboot with sleep:

51 9 5 * * sleep 60 && /usr/sbin/reboot

Or, use shutdown instead, with a delay:

51 9 5 * * /usr/sbin/shutdown -r

shutdown delays the action for a minute by default, but you could use +5 as an argument to delay further. The benefit of using shutdown over reboot in this case is that logins will be denied during the delay (except for root) and that users will get a warning of the impending reboot.

0

The issue was caused by the click not synchronized.

I resolved by doing a cron that run before the reboot with the following command:

/sbin/hwclock --systohc >/dev/null 2>&1

than

/usr/sbin/shutdown -r +5 >/dev/null 2>&1

works.

Without the command mentioned to sync clock the issue persist.

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.