[SOLVED] comand line that would simulate pressing the power button
Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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?
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.
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
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.
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.)
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
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.