How to shutdown the pc on a specific time on terminal?
How to shutdown the pc on a specific time on terminal?
A script or even an app to "poweroff" the pc at a specific time?
really need it.
please some help.
really need it.
please some help.
- Mike Walsh
- Posts: 6351
- Joined: Sat 28 Jun 2014, 12:42
- Location: King's Lynn, UK.
Hi, lolo69.
Amongst the stuff I keep in my 'Puppy-Stuff' data partition, I have a couple of small scripts for those occasions when I want to shut Pup down after a given interval. One is for 30 minutes, the other is for 60 mins. It is, however, a very simple matter to edit the script and substitute the number of minutes required, in order to shut Pup down at the time you want.
Here's the 30-minute one:-
Open Geany, copy'n'paste that into it, then save it with a name you'll recognise. I find the best place to keep it is in /root. Make sure you've made it executable; easiest way is just to rt-clk->Properties, then tick the 'Execute' checkboxes down the bottom, followed by clicking on 'Refresh'. The 'Run action' will change to 'execute', and the script title will change from black text to green.....indicating it's now executable (although using the '#!/bin/sh' prefix on the first line should save it as executable anyway).
To change the value, rt-clk->Open as text, or Open with Geany. Geany should open with the contents of the script. Edit accordingly.....and don't forget to 'Save' before you close Geany.
Hope that helps. You could enter that direct into the terminal.....but you would have to re-type it every time. A script allows the same action to be used again & again, just by clicking on it.
Whenever you need it, just open it in Geany, modify the value accordingly, 'Save', exit.....then click on it. Simple.
-----------------------
@Galbi:-
I think you'll find the instructions on that page you linked to would work fine for mainstream Linux distros.....but of course, we all know Pup is far from being 'mainstream'.
The code I've quoted I discovered here on the Forum somewhere; I forget where, but I know it was quite an old post... It does, however, work perfectly for the inhabitants of my kennels!
Mike.
Amongst the stuff I keep in my 'Puppy-Stuff' data partition, I have a couple of small scripts for those occasions when I want to shut Pup down after a given interval. One is for 30 minutes, the other is for 60 mins. It is, however, a very simple matter to edit the script and substitute the number of minutes required, in order to shut Pup down at the time you want.
Here's the 30-minute one:-
Code: Select all
#!/bin/sh
sleep 30m && wmpoweroff &
To change the value, rt-clk->Open as text, or Open with Geany. Geany should open with the contents of the script. Edit accordingly.....and don't forget to 'Save' before you close Geany.
Hope that helps. You could enter that direct into the terminal.....but you would have to re-type it every time. A script allows the same action to be used again & again, just by clicking on it.
Whenever you need it, just open it in Geany, modify the value accordingly, 'Save', exit.....then click on it. Simple.
-----------------------
@Galbi:-
I think you'll find the instructions on that page you linked to would work fine for mainstream Linux distros.....but of course, we all know Pup is far from being 'mainstream'.
The code I've quoted I discovered here on the Forum somewhere; I forget where, but I know it was quite an old post... It does, however, work perfectly for the inhabitants of my kennels!
Mike.
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Re: How to shutdown the pc on a specific time on terminal?
If you want to shut down at a specific time (and not after an elapsed time) you could try Pschedule. I don't know your Slacko 6.3 but you may find Pschedule in Menu => System => Pschedule task on time.lolo69 wrote:A script or even an app to "poweroff" the pc at a specific time?
Click on "Schedule new task", in the Command field type wmpoweroff, select the desired time for this task and add it to the task list. That should be all.
I'm not sure what "on terminal" in your thread title means. Pschedule is a graphical front-end to create cron jobs. If you really want to use the terminal then Pschedule is not for you. Still I would recommend that you don't mess with crontab files on the command line.
You can use the "at" command, probably not included in any puppy, but you can install it, see here Ubuntu-Trusty packages
https://packages.ubuntu.com/trusty/admin/at
Then, for example, if you want to poweroff the computer at quarter past five:
Fred
https://packages.ubuntu.com/trusty/admin/at
Then, for example, if you want to poweroff the computer at quarter past five:
Code: Select all
echo "poweroff" | at 17:15
- Mike Walsh
- Posts: 6351
- Joined: Sat 28 Jun 2014, 12:42
- Location: King's Lynn, UK.
Re: How to shutdown the pc on a specific time on terminal?
Thanks for the tip on this one, MochiMoppel. I've occasionally looked at this, but never really figured out what it was for.MochiMoppel wrote:If you want to shut down at a specific time (and not after an elapsed time) you could try Pschedule. I don't know your Slacko 6.3 but you may find Pschedule in Menu => System => Pschedule task on time.lolo69 wrote:A script or even an app to "poweroff" the pc at a specific time?
Click on "Schedule new task", in the Command field type wmpoweroff, select the desired time for this task and add it to the task list. That should be all.
I'm not sure what "on terminal" in your thread title means. Pschedule is a graphical front-end to create cron jobs. If you really want to use the terminal then Pschedule is not for you. Still I would recommend that you don't mess with crontab files on the command line.
Now I know! Cheers.
Mike.
This worked for a reboot command in a terminal window
So a script would be something like
Haven't tested it as a script but it should work the same way
Code: Select all
while :; do if [[ $(date +%R) =~ 18:18 ]] ; then reboot ; else sleep 5 ; fi ; done
Code: Select all
#!/bin/sh
shutdowntime=18:18
while :; do if [[ $(date +%R) =~ $shutdowntime ]] ; then reboot ; else sleep 30 ; fi ; done
Works well, nice solution, thanks!theru wrote:This worked for a reboot command in a terminal window
So a script would be something likeCode: Select all
while :; do if [[ $(date +%R) =~ 18:18 ]] ; then reboot ; else sleep 5 ; fi ; done
Haven't tested it as a script but it should work the same wayCode: Select all
#!/bin/sh shutdowntime=18:18 while :; do if [[ $(date +%R) =~ $shutdowntime ]] ; then reboot ; else sleep 30 ; fi ; done
EDIT: For info, just in case someone wants to try this with another command instead of "reboot", for example firefox, make sure to add 'exec' before it, e.g. :
Code: Select all
while :; do if [[ $(date +%R) =~ 18:18 ]] ; then exec firefox ; else sleep 5 ; fi ; done
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Code: Select all
#!/bin/sh
EXEC_START=18:05:30 # '18:00' or just '18' would start command at 6 p.m.
sleep $(( $(date -d $EXEC_START +%s) - $(date +%s) )) # sleeps until 18:05:30
Xdialog -msg "$(date +%X)\nTime to do something" x # sample command