Cron job command for Daily Server Reboot

While tooting on some of my user fellow comments I found out this question quite intrinsic in nature.

Question:

I want to create a cron job which executes daiy at assigned time and it restart the ubuntu server.

I try to add reboot only in cron, but it is not working, whereas it works when I try to execute it from CLI.

Please advise, what command should I add in cron, so that it reboot the server daily at specific time.

Best possible solution:

You need to run the following command:

/sbin/shutdown -r now

with root pirviliges. The way to do it is to use root’s crontab, not your user crontab. A sudo before the usual crontab command does that:

sudo crontab -e

Tip: You can switch the shell’s standard editor for things like crontab and visudo with sudo update-alternatives --config editor and then select the editor of your choice.

Editing the crontab you should add the following line to your file:

# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command  

@daily root /sbin/shutdown -r now

Here is a shortcut for every day at midnight (equivalent to “0 0 * * *”).

Akash Angle

I am a Full time Linux user who has quit using Windows for unknown reasons, making my life truly open source.

Recent Posts

Get the most juice from your ISP/router — setting MTU size & other handy tweaks

This is not an ad-vocation by any means for TP-link branding, however a real life…

6 months ago

How to make any Android phone up-to 3x faster – Developer options unleashed

First of all we need to hit the kernel version on any Android device. You…

6 months ago

systemd-resolve command not found in Ubuntu Desktop

Use resolvectl status instead. It's like something deprecates and suddenly things get broken! In systemd…

11 months ago

How to exclude multiple directories with rsync?

Geeky question: This is what people and friends have tried: rsync -arv --exclude "/home/john/.ccache:/home/ben/build" /home/john…

11 months ago

How to resolve apt-get -f not working

You might encounter this error which appears to be very common on Debian based Distro's…

11 months ago

How to install Broadcom STA wireless drivers on Kali Linux

PS: This article is for only Kali Linux users, that too having a Broadcom Wireless…

12 months ago