help for Restart script

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.
Post Reply
gardenair
Havaldaar
Posts: 106
Joined: Tue Dec 28, 2004 10:07 pm

help for Restart script

Post by gardenair »

I want to shoult down or restart my system at 4 am .Please write the script that should do the specified task.

thanks in advance for the help.
gardenair
lambda
Major General
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Location: Lahore
Contact:

Post by lambda »

type

Code: Select all

echo poweroff | at 0400
if you want to execute multiple commands, put the commands in a file, one per line, and then type

Code: Select all

at -f /path/to/file 0400
read the man page for at.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
x2oxen
Major General
Posts: 1114
Joined: Wed Aug 22, 2007 3:17 pm
Location: Faisalabad
Contact:

Post by x2oxen »

If you want to do it on daily basis you can add a cron job with shutdown command
Muhammad Usman
+92-321-6640501
Chemonics International
http://usmanpk.com
gardenair
Havaldaar
Posts: 106
Joined: Tue Dec 28, 2004 10:07 pm

Post by gardenair »

well what should be the complete script ? and after writing the script in a text editor should i place in /etc folder ? guide me.
eternal peace
Naik
Posts: 86
Joined: Thu Apr 03, 2003 6:44 pm

Post by eternal peace »

There's no need to write a script for that as posted earlier you can do that using crontab only, here's how,

To add the cron job, do,
crontab -e

then, add,

0 4 * * * reboot
or
0 4 * * * poweroff

(to reboot or shutdown system at 4:00 a.m)

save changes and exit.
hail to linux!!!
gardenair
Havaldaar
Posts: 106
Joined: Tue Dec 28, 2004 10:07 pm

Post by gardenair »

chmod +x /etc/cron.daily/sysshutdown


what about it? your suggestions?
x2oxen
Major General
Posts: 1114
Joined: Wed Aug 22, 2007 3:17 pm
Location: Faisalabad
Contact:

Post by x2oxen »

no need to do that.. Just add a cronjob as advised earlier
Muhammad Usman
+92-321-6640501
Chemonics International
http://usmanpk.com
lambda
Major General
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Location: Lahore
Contact:

Post by lambda »

all cron.daily scripts (on my system) run at 6:25am (see your /etc/crontab for details). you could change the time in /etc/crontab, but then some of the scripts in /etc/cron.daily will run, and the rest won't because your shutdown script ran first.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
nomankhn
Colonel
Posts: 714
Joined: Wed Aug 07, 2002 8:00 pm

Post by nomankhn »

I think he is asking home work step by step.?

Thanks,
Noman Liaquat
x2oxen
Major General
Posts: 1114
Joined: Wed Aug 22, 2007 3:17 pm
Location: Faisalabad
Contact:

Post by x2oxen »

Noman that was 15 days ago.. Come move on to new posts :D
Muhammad Usman
+92-321-6640501
Chemonics International
http://usmanpk.com
nomankhn
Colonel
Posts: 714
Joined: Wed Aug 07, 2002 8:00 pm

Post by nomankhn »

x2oxen wrote:Noman that was 15 days ago.. Come move on to new posts :D
i got yesterday na :P

Thanks,
Noman Liaquat
Post Reply