Архив рубрики: start

Cron Daily server reboot

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 than selecting the editor of your choice.

Editing the crontab you should add the following line to you 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

The «@daily» here is a shortcut for every day at midnight (equivalent to «0 0 * * *»). By the way — why do you want a daily reboot?

EDIT — see https://help.ubuntu.com/community/CronHowto for the following: «Crontab commands are generally stored in the crontab file belonging to your user account (and executed with your user’s level of permissions). If you want to regularly run a command requiring administrative permissions, edit the root crontab file: sudo crontab -e»

EDIT — thanks to @charlesbridge for his comment — edited answer to include the full path

start history autorun time

 echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
vim /etc/rc.local
/opt/nginx/sbin/nginx
[root@mx ~]# date
Wed May 13 23:10:23 PDT 2009
yum update tzdata

[root@mx ~]# rm -rf /etc/localtime
[root@mx ~]# ln -s /usr/share/zoneinfo/Europe/Moscow /etc/localtime
[root@mx ~]# date
Thu May 14 10:13:03 MSD 2009