Alright,
I'll assume, that you want to reboot the system whenever it reaches seven days uptime..
Keep on with me, and follow the instructions..
First, we will create a new script, shell script, run:
Code:
nano /bin/RestartMe
Then, copy and paste the following (Copy from here and then right click into the Putty's window to paste it):
Code:
#!/bin/bash
up=$(/usr/bin/uptime | cut -c14-19)
if [[ "$up" = "7 days" ]]; then
/sbin/shutdown -r +2
fi
exit 0
# END
And, then close and save the file
Code:
CTRL + X then Hit Y and then ENTER
Change the file mode to executable:
Code:
chmod 755 /bin/RestartMe
Now, we are done with the reboot script, we will setup a cronjob to run every night:
To open crontab editor:
and then at the end type the followin:
Code:
30 2 * * * /bin/RestartMe
Summary:
The crontab we sat above, will run the script every night at 2:30 AM server time, thus the script will check for the server uptime, if it's 7 days, a system reboot will be fired.
The reboot command will wait 2 minutes before doing the real reboot, this way it gives a chance for any logged user to finish any running work.
Otherwise, if you want to reboot the system on Sunday after 2 after midnigh (Monday Early Morning), no matter how long is the uptime.. go like:
At the end type:
Code:
30 2 * * 1 /bin/RestartMe
Hope we helped.. :-)
Regards..