How to shutdown the pc on a specific time on terminal?

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
lolo69
Posts: 77
Joined: Sun 01 Oct 2017, 17:08
Location: Your heart <3

How to shutdown the pc on a specific time on terminal?

#1 Post by lolo69 »

A script or even an app to "poweroff" the pc at a specific time?

really need it.

please some help.

User avatar
Galbi
Posts: 1098
Joined: Wed 21 Sep 2011, 22:32
Location: Bs.As. - Argentina.

#2 Post by Galbi »

Remember: [b][i]"pecunia pecuniam parere non potest"[/i][/b]

User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

#3 Post by Mike Walsh »

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:-

Code: Select all

#!/bin/sh
sleep 30m && wmpoweroff &
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. :wink:

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Re: How to shutdown the pc on a specific time on terminal?

#4 Post by MochiMoppel »

lolo69 wrote:A script or even an app to "poweroff" the pc at a specific time?
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.

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.

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#5 Post by fredx181 »

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:

Code: Select all

echo "poweroff" | at 17:15
Fred

User avatar
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?

#6 Post by Mike Walsh »

MochiMoppel wrote:
lolo69 wrote:A script or even an app to "poweroff" the pc at a specific time?
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.

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.
Thanks for the tip on this one, MochiMoppel. I've occasionally looked at this, but never really figured out what it was for.

Now I know! Cheers.


Mike. :wink:

theru
Posts: 163
Joined: Thu 23 Jul 2015, 16:40
Location: Heers, Belgium

#7 Post by theru »

This worked for a reboot command in a terminal window

Code: Select all

while :; do if [[ $(date +%R) =~ 18:18 ]] ; then reboot ; else sleep 5 ; fi ; done
So a script would be something like

Code: Select all

#!/bin/sh

shutdowntime=18:18

while :; do if [[ $(date +%R) =~ $shutdowntime ]] ; then reboot ; else sleep 30 ; fi ; done
Haven't tested it as a script but it should work the same way

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#8 Post by fredx181 »

theru wrote:This worked for a reboot command in a terminal window

Code: Select all

while :; do if [[ $(date +%R) =~ 18:18 ]] ; then reboot ; else sleep 5 ; fi ; done
So a script would be something like

Code: Select all

#!/bin/sh

shutdowntime=18:18

while :; do if [[ $(date +%R) =~ $shutdowntime ]] ; then reboot ; else sleep 30 ; fi ; done
Haven't tested it as a script but it should work the same way
Works well, nice solution, thanks!

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
Fred

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#9 Post by MochiMoppel »

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

Post Reply