LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-02-2005, 12:33 PM   #1
Devils_Knight
LQ Newbie
 
Registered: Oct 2004
Location: Australia
Posts: 18

Rep: Reputation: 0
Arrow Scheduled shutdown?


Just like to know if there is away to schedule my computer to shutdown.
Running Mandrake 10
Thanks.
 
Old 02-02-2005, 12:44 PM   #2
masand
LQ Guru
 
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522

Rep: Reputation: 69
write a simple C program or script

like this C program
---------
void main()
{
sleep(3000);

system("shutdown -h now");
}
~
this will shutdown my system after 3000secs=50 minutes
compile this and use this
regards
-----------
 
Old 02-02-2005, 01:01 PM   #3
Devils_Knight
LQ Newbie
 
Registered: Oct 2004
Location: Australia
Posts: 18

Original Poster
Rep: Reputation: 0
Ermm? where and how can I do this? Exatly.
 
Old 02-02-2005, 01:07 PM   #4
masand
LQ Guru
 
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522

Rep: Reputation: 69
have u complied a C program earlier

regards
 
Old 02-02-2005, 01:18 PM   #5
Devils_Knight
LQ Newbie
 
Registered: Oct 2004
Location: Australia
Posts: 18

Original Poster
Rep: Reputation: 0
I'v compiled stuff before.... programs, but not anything like this.
I tryed the first part.
[*name*@localhost *name*]$ void main()
bash: syntax error near unexpected token `('
[*name*@localhost *name*]$

Any chance of showing me step-by-step ?
 
Old 02-02-2005, 01:30 PM   #6
Gato Azul
Member
 
Registered: Sep 2003
Location: /dev/null
Distribution: CentOS, Ubuntu
Posts: 128

Rep: Reputation: 16
Open up a text editor such as vim or emacs or pico (I won't go into which one is best ). Then copy the text into the document you have open, save it and compile. Here would be the steps:

with EMACS:

user@host:$ emacs shutdownprog.c

(now paste the program in...highlight it from here and do a middle mouse click [or both buttons at once] into the terminal window)

void main()
{
sleep(3000);

system("shutdown -h now");
}

Now save and exit - type ctrl + x then ctrl + s to save, and ctrl + x then ctrl + c to quit

then type gcc shutdownprog.c

It'll make an executable called a.out. To run the executable, type ./a.out

with VI (or VIM):

user@host:$ vi shutdownprog.c

hit the i key to enter insert mode (where you can type text)

(now paste the program in...highlight it from here and do a middle mouse click [or both buttons at once] into the terminal window)

void main()
{
sleep(3000);

system("shutdown -h now");
}

Now save and exit - hit the Esc key and type :wq and hit enter

then type gcc shutdownprog.c

It'll make an executable called a.out. To run the executable, type ./a.out

Last edited by Gato Azul; 02-02-2005 at 02:46 PM.
 
Old 02-02-2005, 01:38 PM   #7
Artanicus
Member
 
Registered: Jan 2005
Location: Finland
Distribution: Ubuntu, Debian, Gentoo, Slackware
Posts: 827

Rep: Reputation: 31
if you want a more dynamic solution, here are a few ideas:

use at (if installed) or cron to time it.. And example at session:
Code:
[root@indigo] ~# at 22:00
warning: commands will be executed using (in order) a) $SHELL b) login shell c) /bin/sh
at> shutdown -h now
at> <EOT> # I pressed ctrl+d to mark the job as done
job 51 at 2005-02-02 22:00
The same could be achieved via a cron, but thats a tad too much of shooting a mouse with a shotgun..

The final and simples way would be just to use this:

Code:
sleep 30m && shutdown -h now
# or 
sleep 5h && shutdown -h now
Via these ways you dont have to hardcode the time into the C code binding you to the same shutdown time every night
 
Old 02-02-2005, 01:59 PM   #8
Devils_Knight
LQ Newbie
 
Registered: Oct 2004
Location: Australia
Posts: 18

Original Poster
Rep: Reputation: 0
"then type gcc shutdownprog.c"

When I done that, the konsole done nothing... should I just close it and it will be ok?
 
Old 02-02-2005, 02:13 PM   #9
masand
LQ Guru
 
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522

Rep: Reputation: 69
after that run

./a.out

and then do not close that terminal or u will have that program exiting

regards
 
Old 02-02-2005, 02:15 PM   #10
Devils_Knight
LQ Newbie
 
Registered: Oct 2004
Location: Australia
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks for all the help guys, got me even more interested in this.
 
Old 02-02-2005, 02:21 PM   #11
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Umm... what is up with all these complex solutions? *grin*

How about this:
Code:
shutdown -h 22:00
that will shutdown the system at 10 pm.

No cron, at, C, or voodoo needed.
 
Old 02-02-2005, 02:24 PM   #12
Artanicus
Member
 
Registered: Jan 2005
Location: Finland
Distribution: Ubuntu, Debian, Gentoo, Slackware
Posts: 827

Rep: Reputation: 31
Quote:
Originally posted by Matir
Umm... what is up with all these complex solutions? *grin*

How about this:
Code:
shutdown -h 22:00
that will shutdown the system at 10 pm.

No cron, at, C, or voodoo needed.
mjeh, was laughing to my beard the same thing.. wasnt sure on the syntax and didnt bother to check so kept my mouth shut and quicly gave a pretties solution to a stiff C version.. (;

But as said, shutdown itself has a pretty useful timing system.. its manual is worth a read to make sure the syntax is right before you test it and accidentaly shutdown immediately.. (:

Last edited by Artanicus; 02-02-2005 at 02:25 PM.
 
Old 02-02-2005, 02:34 PM   #13
masand
LQ Guru
 
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522

Rep: Reputation: 69
yes that will better than my C program i think

/sbin/shutdown [-t sec] [-arkhncfF] time [warning-message]

man shutdown

regards
 
Old 02-02-2005, 02:43 PM   #14
Gato Azul
Member
 
Registered: Sep 2003
Location: /dev/null
Distribution: CentOS, Ubuntu
Posts: 128

Rep: Reputation: 16
Quote:
Matir said:
Umm... what is up with all these complex solutions? *grin*
Oh come on, where's your sense of adventure??? There's never any fun in taking the easy way out!
 
Old 02-02-2005, 02:58 PM   #15
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Quote:
Originally posted by Gato Azul
Oh come on, where's your sense of adventure??? There's never any fun in taking the easy way out!
LOL, fair enough. Of course, I rarely use a baseball bat to get in my car when the keys in my pocket work just as well.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Scheduled RSS printer jc2464 Linux - Software 0 10-23-2005 09:54 PM
Scheduled tasks? onionkn1ght Linux - Software 3 01-11-2005 11:20 PM
when is next slack scheduled? larva828 Slackware 5 11-01-2004 08:36 PM
Scheduled tasks... beserier Linux - General 1 01-24-2003 09:55 AM
scheduled maintenance adenardo Linux - General 1 12-23-2002 02:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration