LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 09-05-2021, 08:45 PM   #1
krazyivan
LQ Newbie
 
Registered: Jan 2012
Posts: 29

Rep: Reputation: Disabled
Question comand line that would simulate pressing the power button


Hi,
I am lazy and often fall asleep watching anime on my pc.Trying to conserve energy I'm looking for a way to put the shutdown dialog (as if I were to press the powerbutton) in crontab. Why the dialog and not just `shutdown -h now` you ask? I sometimes work/play late at night on that pc as well, so a dialog window waiting 30 sec that would not kill all my work sounds perfect.
ps. I'm a KDE user.

thanks in advance
 
Old 09-06-2021, 01:11 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by krazyivan View Post
I am lazy and often fall asleep watching anime on my pc.Trying to conserve energy I'm looking for a way to put the shutdown dialog (as if I were to press the powerbutton) in crontab. Why the dialog and not just `shutdown -h now` you ask? I sometimes work/play late at night on that pc as well, so a dialog window waiting 30 sec that would not kill all my work sounds perfect.
Doesn't compute.
If you're asleep you cannot save your work anyhow, whether the command waits 30s or not???

In any case, I think you missed one of the options that does exactly what you want, when you were reading shutdown's man page.
You did that before asking here, didn't you?
 
Old 09-06-2021, 02:19 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,359
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
The shutdown utility can take time, either relative or absolute.

Code:
sudo shutdown -h +5 'Done for the day'

sudo shutdown -h 23:30 'Done for the day'
Another option would be to either suspend or hibernate the system using the pm-suspend or pm-hibernate utilities. That would more or less poweroff your hardware yet let you resume where you left off once you wake the system up again.

Code:
echo pm-suspend | sudo at now +5 minutes

echo pm-suspend | sudo at 23:30
If you're careful, you could even launch your movie in such a way that the system suspends after it is finished playing.
 
Old 09-06-2021, 07:37 AM   #4
krazyivan
LQ Newbie
 
Registered: Jan 2012
Posts: 29

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
Doesn't compute.
If you're asleep you cannot save your work anyhow, whether the command waits 30s or not???
Let me rephrase that in a more understandable manner: There are nights when I fall asleep watching a show, there are also nights when I work late and I use the same PC.
That is why I'm looking for an interactive shudown command - to shutdown in the first case but ask me in the latter.

Quote:
Originally Posted by Turbocapitalist View Post
The shutdown utility can take time, either relative or absolute.

Code:
sudo shutdown -h +5 'Done for the day'

sudo shutdown -h 23:30 'Done for the day'
Code:
echo pm-suspend | sudo at now +5 minutes

echo pm-suspend | sudo at 23:30
thanks, I know those commands but none of those are interactive from the X level. As mentioned - X user interaction is crucial for this use case.
 
Old 09-06-2021, 07:48 AM   #5
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,628

Rep: Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557
Quote:
Originally Posted by Turbocapitalist View Post
If you're careful, you could even launch your movie in such a way that the system suspends after it is finished playing.
This would seem to be the best approach - it's both simpler and addresses the actual issue.

(The technical one at least - if one is frequently falling asleep whilst watching something, consider figuring out why that is and solving that problem.)

 
Old 09-06-2021, 07:49 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,359
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
Quote:
Originally Posted by krazyivan View Post
thanks, I know those commands but none of those are interactive from the X level. As mentioned - X user interaction is crucial for this use case.
Then put them together with some others. Here is one with xmessage but there are many alternatives to it around. The main option here is -timeout but you could even use the timeout utility from coreutils instead.

Code:
echo "DISPLAY=:0.0 xmessage -buttons Ok:0,\"Not sure\":1,Cancel:2 -default Ok -nearmouse \"Sleep ?\" -timeout 20 && sudo pm-suspend" | at now +5 minutes
Then you'd need something corresponding in /etc/sudoers

Code:
%krazyivan ALL=(root:root) NOPASSWD: /usr/sbin/pm-suspend ""
or something like that.
 
1 members found this post helpful.
Old 09-06-2021, 08:07 AM   #7
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,628

Rep: Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557
Quote:
Originally Posted by Turbocapitalist View Post
Then you'd need something corresponding in /etc/sudoers
I don't need to sudo with "systemctl hibernate" or "systemctl poweroff" and I don't recall configuring that.

(Using hibernate instead of shutdown would address the possibility of starting a movie with unsaved work in the background.)

 
Old 09-06-2021, 08:16 AM   #8
krazyivan
LQ Newbie
 
Registered: Jan 2012
Posts: 29

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
Code:
echo "DISPLAY=:0.0 xmessage -buttons Ok:0,\"Not sure\":1,Cancel:2 -default Ok -nearmouse \"Sleep ?\" -timeout 20 && sudo pm-suspend" | at now +5 minutes
.
This was my puzzle's missing piece - I forgot that xmessage can have a timeout. It fits my usecase just perfect.
Thanks Turbocapitalist, You solved my issue!

Last edited by krazyivan; 09-06-2021 at 08:18 AM.
 
Old 09-06-2021, 08:48 AM   #9
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,359
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
No problem. For what it's worth, yad and zenity also have timeout options.
 
  


Reply

Tags
automation, kde, shutdown



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is possible to simulate Load balancing algorithms using NS-2?for example i am trying to simulate Least Connection algorithm. mariio Linux - Networking 3 05-05-2016 08:06 AM
Howto use xmacroplay-keys to simulate pressing ALT + RETURN ? frenchn00b Linux - General 7 06-11-2013 03:30 PM
[SOLVED] How to eject & close cdrom with command not manually by pressing button sumeet inani Linux - Newbie 2 06-22-2009 06:29 AM
How to simulate a ENTER key pressing khaos83 Linux - Newbie 2 08-06-2008 04:41 AM
Evolution crashing when pressing any button! steste Linux - Software 1 06-22-2008 04:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 04:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration