Forum
« Script to shutdown in x minutes »

Welcome Guest. Please Login or Register.
May 21, 2013, 9:20pm



Return to or visit the SalineOS webpage

Forum :: General :: Software and Applications :: Script to shutdown in x minutes
   [Search This Thread] [Share Topic] [Print]
 AuthorTopic: Script to shutdown in x minutes (Read 444 times)
desputin
New Member
*
member is offline





Joined: Aug 2011
Gender: Male
Posts: 13
 Script to shutdown in x minutes
« Thread Started on Apr 24, 2012, 1:15pm »

Hi, as there is nothing like Kshutdown for xfce I would like to write a bash script that opens the terminal window and shuts down the system in x minutes. Let's say 5 minutes.

Anyone here know how to write such a script?

best regards
desputin
Link to Post - Back to Top  IP: Logged
Anthony Nordquist
Administrator
*****
member is offline




[homepage]

Joined: Dec 2010
Gender: Male
Posts: 1,336
 Re: Script to shutdown in x minutes
« Reply #1 on Apr 24, 2012, 2:49pm »

Code:
#!/bin/bash
shutdown -h +5
exit


This will need to be run as root.

To open a terminal and run the script you would create another script like so:
Code:
#!/bin/bash
exec /usr/bin/xfce4-terminal -x /path/to/first/script/script-name
exit
« Last Edit: Apr 24, 2012, 2:55pm by Anthony Nordquist »Link to Post - Back to Top  IP: Logged
wh7qq
Junior Member
**
member is offline





Joined: Apr 2011
Gender: Male
Posts: 50
Location: Hawaii
 Re: Script to shutdown in x minutes
« Reply #2 on Apr 24, 2012, 4:14pm »

Another approach is to use "at". I think I had to add it to SalineOS but can't be sure of that. I use it for scheduling downloads for my ISP's "free time" by doing an "at" command:
Code:
# at 00:05 tomorrow
warning: commands will be executed using /bin/sh
at> wget [url]http://www.salineos.com/Downloads/SalineOS-1.6-i386.iso[/url]
at> poweroff
at> <EOT>
job 53 at Wed Apr 25 00:05:00 2012

# at 05:55 tomorrow
warning: commands will be executed using /bin/sh
at> poweroff
at> <EOT>




I do the second "poweroff" command to be sure that I don't get hit for the full download because it was slow and ran over the "free time"

"at" command sequences are always terminated with a Ctrl-D and the actual job file is saved in /var/spool/cron/atjobs which must be opened as root. System commands such as "poweroff" must be run as root so the entire at job must also be run as root. Deleting an at job file will prevent it from happening if you change your mind.

The "at" command has an unusually rich and easy to use set of time specifications such as "now" or "tomorrow" or "tea-time"

For more detailed instructions, see
Code:
man at
« Last Edit: Apr 25, 2012, 12:34am by wh7qq »Link to Post - Back to Top  IP: Logged
desputin
New Member
*
member is offline





Joined: Aug 2011
Gender: Male
Posts: 13
 Re: Script to shutdown in x minutes
« Reply #3 on Apr 24, 2012, 4:38pm »

Thank you. First I will try the easy way with the two shell scripts...
Link to Post - Back to Top  IP: Logged
debby
Full Member
***
member is offline





Joined: Nov 2011
Gender: Male
Posts: 124
 Re: Script to shutdown in x minutes
« Reply #4 on Apr 27, 2012, 8:26am »

In trying to create an automated script, I installed expect-lite and after much head scratching discovered that you will need it to be interactive and preferably twice. Once to login as root and once to input your desired time in hr,m,s. Based upon

#!/bin/bash
shutdown -h +5
exit

it looks simple enough but is far from it:)

The above script does the job by itself (as root) but gives a newline error. more head scratching :D
« Last Edit: Apr 27, 2012, 12:21pm by debby »Link to Post - Back to Top  IP: Logged
fanch
Junior Member
**
member is offline

[avatar]


[homepage]

Joined: Mar 2011
Gender: Male
Posts: 69
Location: France
 Re: Script to shutdown in x minutes
« Reply #5 on May 22, 2012, 6:12pm »

hello,

there is a plugin that can add to the panel that makes it all very easy: Xfce4-timer-plugin. ;)
Link to Post - Back to Top  IP: Logged

"The candle loses nothing of its light by communicating it to another candle."
http://counter.li.org/cgi-bin/certificate.cgi/476703
   [Search This Thread] [Share Topic] [Print]



Anthony Nordquist, on behalf of the SalineOS project, is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com. As such, if you click the above banner and then make any purchase including digital downloads, a small percentage will be paid to the SalineOS project.
Click Here To Make This Board Ad-Free


This Board Hosted For FREE By ProBoards
Get Your Own Free Message Boards & Free Forums!
Terms of Service | Privacy Policy | Notice | FTC Disclosure | Report Abuse | Mobile