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
| |
|
Anthony Nordquist Administrator
     member is offline
![[homepage] [homepage]](http://images.proboards.com/new/buttons/www_sm.png) Joined: Dec 2010 Gender: Male  Posts: 1,343
|  | 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
|
|
| |
|
wh7qq Junior Member
  member is offline
Joined: Apr 2011 Gender: Male  Posts: 52 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:
| |
|
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...
| |
|
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
| |
|
fanch Junior Member
  member is offline
![[avatar] [avatar]](http://pix.toile-libre.org/upload/original/1346974548.gif)
![[homepage] [homepage]](http://images.proboards.com/new/buttons/www_sm.png) 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.
|
|
|