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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
02-02-2005, 12:33 PM
|
#1
|
LQ Newbie
Registered: Oct 2004
Location: Australia
Posts: 18
Rep:
|
Scheduled shutdown?
Just like to know if there is away to schedule my computer to shutdown.
Running Mandrake 10
Thanks.
|
|
|
02-02-2005, 12:44 PM
|
#2
|
LQ Guru
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522
Rep:
|
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
-----------
|
|
|
02-02-2005, 01:01 PM
|
#3
|
LQ Newbie
Registered: Oct 2004
Location: Australia
Posts: 18
Original Poster
Rep:
|
Ermm? where and how can I do this? Exatly.
|
|
|
02-02-2005, 01:07 PM
|
#4
|
LQ Guru
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522
Rep:
|
have u complied a C program earlier
regards
|
|
|
02-02-2005, 01:18 PM
|
#5
|
LQ Newbie
Registered: Oct 2004
Location: Australia
Posts: 18
Original Poster
Rep:
|
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 ?
|
|
|
02-02-2005, 01:30 PM
|
#6
|
Member
Registered: Sep 2003
Location: /dev/null
Distribution: CentOS, Ubuntu
Posts: 128
Rep:
|
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.
|
|
|
02-02-2005, 01:38 PM
|
#7
|
Member
Registered: Jan 2005
Location: Finland
Distribution: Ubuntu, Debian, Gentoo, Slackware
Posts: 827
Rep:
|
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
|
|
|
02-02-2005, 01:59 PM
|
#8
|
LQ Newbie
Registered: Oct 2004
Location: Australia
Posts: 18
Original Poster
Rep:
|
"then type gcc shutdownprog.c"
When I done that, the konsole done nothing... should I just close it and it will be ok?
|
|
|
02-02-2005, 02:13 PM
|
#9
|
LQ Guru
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522
Rep:
|
after that run
./a.out
and then do not close that terminal or u will have that program exiting
regards
|
|
|
02-02-2005, 02:15 PM
|
#10
|
LQ Newbie
Registered: Oct 2004
Location: Australia
Posts: 18
Original Poster
Rep:
|
Thanks for all the help guys, got me even more interested in this.
|
|
|
02-02-2005, 02:21 PM
|
#11
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep:
|
Umm... what is up with all these complex solutions? *grin*
How about this:
that will shutdown the system at 10 pm.
No cron, at, C, or voodoo needed.
|
|
|
02-02-2005, 02:24 PM
|
#12
|
Member
Registered: Jan 2005
Location: Finland
Distribution: Ubuntu, Debian, Gentoo, Slackware
Posts: 827
Rep:
|
Quote:
Originally posted by Matir
Umm... what is up with all these complex solutions? *grin*
How about this:
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.
|
|
|
02-02-2005, 02:34 PM
|
#13
|
LQ Guru
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522
Rep:
|
yes that will better than my C program i think
/sbin/shutdown [-t sec] [-arkhncfF] time [warning-message]
man shutdown
regards
|
|
|
02-02-2005, 02:43 PM
|
#14
|
Member
Registered: Sep 2003
Location: /dev/null
Distribution: CentOS, Ubuntu
Posts: 128
Rep:
|
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!
|
|
|
02-02-2005, 02:58 PM
|
#15
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 05:11 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|