Announcement

Collapse
No announcement yet.

Shutdown delay x number of seconds

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Shutdown delay x number of seconds

    I'm trying to create a shutdown shortcut so I can shut down or reboot the computer with a keystroke with a delay in seconds.

    The shortcut is easy enough to set up. But the command is not working as expected.

    What I expect is that this command will cause the computer to begin rebooting 3 seconds after it is executed.
    shutdown -r -t 3
    or
    shutdown -r -t 03

    What happens:
    It reboots one minute after the command is executed.

    How do I get the shutdown command to delay more than 0 but less than 60 seconds?

    #2
    If you see man shutdown , it looks like seconds are not contemplated. You could try sleep 3;shutdown -r now
    To test, you might try: sleep 3;echo hello

    Comment


      #3
      Using the shutdown command (or the systemd command that it runs) is not nice to your desktop environment, it just gets killed.

      The nice KDE way is to send a DBUS message:
      Code:
      qdbus org.kde.ksmserver /KSMServer logout 1 2 3
      but I don't know how to change the 30 s time.
      Regards, John Little

      Comment


        #4
        Originally posted by Don B. Cilly View Post
        If you see man shutdown , it looks like seconds are not contemplated. You could try sleep 3;shutdown -r now
        To test, you might try: sleep 3;echo hello
        sleep 3 does indeed work to delay it. But it defeats the purpose that I had in mind with the x second delay, which is to be able to cancel the shut down if it I triggered it prematurely.

        I find it a bit odd that there is an option for minutes delay but not for seconds delay.

        There seem to be some references to this on the web

        https://www.linuxquestions.org/quest...econds-806526/

        But it doesn't seem to work that way in Kubuntu. Odd.

        Comment


          #5
          Well, I guess that's why the pre-defined shortcuts for shutdown and reboot (without confirmation) are Ctrl-Alt-Shift-PgDown an PgUp. Difficult to do by mistake.
          You'll find them under system settings/shortcuts/ksmserver, btw.

          Another workaround may be... [play sound];sleep;shutdown now.
          You hear the sound, you have another shortcut for shutdown -c (cancel). Which might work... :·/
          But, as jlittle says, shutdown now is "not nice"...

          ... even though, I remember, years ago I had a Mint KDE installation where the shutdown menu disappeared, and Ctrl-Alt-Del wouldn't work either..
          I made a big red button with a DO NOT TOUCH label in the tray that would do that, used it for a while, and was never aware of any problems...

          ... I guess "complicated" shortcuts (like the default ones) are probably a good compromise.
          Last edited by Don B. Cilly; Sep 24, 2019, 01:42 AM.

          Comment


            #6
            Shutdown does not, as mentioned, not support seconds for the delay TIME.

            From the cli you could do something like
            Code:
            [FONT=monospace][COLOR=#18B218]echo[/COLOR] [COLOR=#B26818]"Shutdown in 5 seconds"[/COLOR] && [COLOR=#18B218]sleep[/COLOR] 5 && [COLOR=#18b218]shutdown -h now[/COLOR][/FONT]
            Which would give you 5 seconds to hit Ctrl+c to cancel. However, you shouldn't do that if you are running a GUI desktop as it would not exit cleanly (as jlittle pointed out)...from GUI I guess you could have a script that shows a kdialog window (for possible cancel), waits a few seconds and runs the dbus call to ksmserver if cancel hasn't been pressed (or optional OK has been pressed)...or something along those lines.

            Or you could try out what options kshutdown offers (I haven't had it installed for ages, so I really can't tell), maybe it has some keyboard shortcuts (or dbus calls) you'd find usable.
            (EDIT: looks like ksutdown also does not allow delay in seconds, so you'd have to use sleep with it too...not an optimal solution it seems)
            Last edited by kubicle; Sep 24, 2019, 03:14 AM.

            Comment


              #7
              I'm no kernel programmer, but I'm assuming that shutdown is written and intended to be a command line only program based on the user knowing what he/she is doing. Also, that shutdown as a command line program is not concerned with a GUI environment - there are other services that take care of closing out the GUI much better. So shutdown is written correctly, but may not be the best solution for an orderly closing of a GUI and the system as a whole.
              The next brick house on the left
              Intel i7 11th Gen | 16GB | 1TB | KDE Plasma 5.27.11​| Kubuntu 24.04 | 6.8.0-31-generic



              Comment


                #8
                Originally posted by jglen490 View Post
                I'm no kernel programmer, but I'm assuming that shutdown is written and intended to be a command line only program based on the user knowing what he/she is doing. Also, that shutdown as a command line program is not concerned with a GUI environment - there are other services that take care of closing out the GUI much better. So shutdown is written correctly, but may not be the best solution for an orderly closing of a GUI and the system as a whole.
                If you go to the start menu (What is it called in Linux?) and click on `Leave` then right-click on Shutdown and add it to favorites, you can inspect the actual command by right-clicking and choosing `Edit Application`. The command issued is `shutdown -P now`

                It would be nice to able to set a delay in seconds.

                Is there a Linux feature request site somewhere?

                Comment


                  #9
                  Originally posted by TwoFistedJustice View Post
                  The command issued is `shutdown -P now`
                  That's probably the final step in running the shutdown, but the shutdown icon does more than that to make sure the desktop session ends cleanly (so you still shouldn't under normal circumstances run that directly in a GUI).

                  You can test it quite easily, for example, open a kate window and type some garbage in it (so you have unsaved changes)...if you try to shutdown from the GUI shutdown icon, a window will pop up asking you to save your unsaved changes (and you can also cancel the shutdown completely if you wish)...if you run "shutdown -P now" from a terminal, the session is just killed, no save confirmation window presented (also, session isn't saved if you have configured restored sessions etc.).

                  (As a side note, the "shutdown" command is handled by systemd now, at least on *buntus, as /sbin/shutdown is just a symlink to /bin/systemctl, so if you wish to file a feature request for a "seconds delay" you should probably direct it at them, but I wouldn't hold my breath for it...and anyway you shouldn't use shutdown directly from a GUI, as mentioned.)

                  Comment


                    #10
                    I apologise in advance if I seem insistent, but... Ctrl-Alt-Shift-PgDown (pre-installed default) should be good enough, shouldn't it?
                    I mean, assuming the delay is meant as a "safeguard" in case you use the shortcut by mistake. In which case, [play sound];sleep;shutdown now would also "work".

                    I understand how we like to customise things to our liking, but... how often are you going to use Ctrl-Alt-Shift-PgDown (or Up) by mistake?
                    And even if you do, it doesn't exactly wipe your disk, does it?

                    Comment


                      #11
                      Originally posted by Don B. Cilly View Post
                      I apologise in advance if I seem insistent, but... Ctrl-Alt-Shift-PgDown (pre-installed default) should be good enough, shouldn't it?
                      I mean, assuming the delay is meant as a "safeguard" in case you use the shortcut by mistake. In which case, [play sound];sleep;shutdown now would also "work".

                      I understand how we like to customise things to our liking, but... how often are you going to use Ctrl-Alt-Shift-PgDown (or Up) by mistake?
                      And even if you do, it doesn't exactly wipe your disk, does it?
                      I have set up my systems since Windows 95 to use CTRL+ALT+U to shut down and CTRL+ALT+R to reboot. These are also pretty hard to hit accidentally and quite a bit easier to hit deliberately. I have continued that practice with Linux. Since I don't use other CTRL+ALT shortcuts this works pretty well for me.

                      Comment


                        #12
                        Well, if they are hard enough for you to hit accidentally, why not switch to those in System setting, shortcuts, ksmserver?

                        Comment


                          #13
                          Originally posted by kubicle View Post
                          That's probably the final step in running the shutdown, but the shutdown icon does more than that to make sure the desktop session ends cleanly (so you still shouldn't under normal circumstances run that directly in a GUI).

                          You can test it quite easily, for example, open a kate window and type some garbage in it (so you have unsaved changes)...if you try to shutdown from the GUI shutdown icon, a window will pop up asking you to save your unsaved changes (and you can also cancel the shutdown completely if you wish)...if you run "shutdown -P now" from a terminal, the session is just killed, no save confirmation window presented (also, session isn't saved if you have configured restored sessions etc.).

                          (As a side note, the "shutdown" command is handled by systemd now, at least on *buntus, as /sbin/shutdown is just a symlink to /bin/systemctl, so if you wish to file a feature request for a "seconds delay" you should probably direct it at them, but I wouldn't hold my breath for it...and anyway you shouldn't use shutdown directly from a GUI, as mentioned.)
                          I have tested it as you said and it behaved as you described.

                          Are the the icons in the 'leave' menu just symlinks pointing to one or more files containing a script?

                          If they are couldn't I conceivably copy the script and change the timeout to get the result I want, which is a very quick non-damaging shutdown?

                          [EDIT]

                          I have also tested what happens if you add the shutdown shortcut in the leave menu to favorites and click on that. It behaves exactly like the one I created. It kills an unsaved Kate window. So there must be something special about the Leave menu itself.
                          Last edited by TwoFistedJustice; Sep 25, 2019, 04:17 PM.

                          Comment


                            #14
                            I poke around a bit in terminal and inspected all the non-graphical shutdown files. They look like compiled files. So no joy there.

                            I did some searching around the web and found a thread on "Shutdown kde correctly from command-line"

                            https://forum.kde.org/viewtopic.php?t=88022

                            I haven't tried it yet because I don't have a clue what it actually does yet or whether it is even compatible with the current version of KDE.

                            Comment


                              #15
                              Those are still valid today. I was going to post a similar but newer link that gives the same info.

                              Comment

                              Working...
                              X