Suspend – Command Line – help?

Forum Forums New users New Users and General Questions Suspend – Command Line – help?

  • This topic has 25 replies, 5 voices, and was last updated Aug 15-12:44 pm by rej.
Viewing 15 posts - 1 through 15 (of 26 total)
  • Author
    Posts
  • #11667
    Member
    rej

      Tried to edit this file (as root) in /usr/local/bin/desktop-session-exit

      From, line 39
      sudo pm-suspend
      to
      ————
      sudo sleep 6s; sudo pm-suspend
      _______________________

      Did not work – reduced it to 6s for testing and the indicator light for sleep on the PC flickered – looked like it was trying, but never succeeded.

      Is there another way to set suspend for LXDE, Fluxbox and IceWM?

      Thank you.

      #11668
      Member
      fatmac
        Helpful
        Up
        0
        ::

        Maybe make it a single command – I think that would be something like,

        ‘sudo sleep 6s && pm-suspend’

        (Guessing, but maybe worth a try.)

        Linux (& BSD) since 1999

        #11675
        Member
        rej
          Helpful
          Up
          0
          ::

          fatmac-

          Thanks! Tried it – no success.

          Did I do it wrong?

          This is how text was entered (root edit-saved) no sleep after 10 minutes –
          [found the first 2 online forum: https://www.cyberciti.biz/faq/linux-command-to-suspend-hibernate-laptop-netbook-pc/ ]

          The echo lines are tabbed in once, which is not reflected here upon “submit”.
          ________________________________________
          fi
          ;;
          -S|–suspend)
          sudo pm-suspend
          echo ‘systemctl suspend’ | at now + 6 minutes
          ;;
          ________________________________________
          fi
          ;;
          -S|–suspend)
          sudo pm-suspend
          echo ‘pm-suspend’ | at now + 6 minutes
          ;;
          ________________________________________
          fi
          ;;
          -S|–suspend)
          sudo sleep 6s && pm-suspend
          ;;
          ———————–

          Also tried installing another Power Manager in Synaptic – did not work either.

          Maybe it needs a plugin or another package installed?

          #11678
          Member
          fatmac
            Helpful
            Up
            0
            ::

            It was just a guess, but looking at your samples, it looks like the commands are being piped (|), so I’d try changing ‘minutes’ to ‘seconds’, & see what happens.

            The ‘at now + 6 minutes’ is telling it to wait 6 mins before carrying out the command.

            (I’m not a programmer, but did dabble a few years ago.)

            Linux (& BSD) since 1999

            #11683
            Member
            rej
              Helpful
              Up
              0
              ::

              fatmac-

              Went back to Synaptic to try Xfce4 power Manager, even though I do not have Xfce desktop installed, and it failed to install with an error notification popup. Gnome Power Manager had installed, yet could not be accessed to set it up. Used command line install of Xfce Power Mngr and it was successful. Tested it out and it suspends exactly in time set and is automatic on startup – runs in IceWM, Fluxbox, and LXDE.

              The following edits were attempted prior to installing Power Mngr, but did not work. Again, the line beginning with “echo” is tabbed over once even though it doesn’t show up that way in the post. Waited 15 minutes to test each one just to be sure.

              I am curious as to whether or not they were entered correctly. Please let me know if they were not. If they are correct, could something in the system be blocking?

              Thanks again for your help!

              fi
              ;;
              -S|–suspend)
              sudo pm-suspend
              echo ‘systemctl suspend’ | at now + 360s
              ;;
              -r|–reboot)
              ___________________________________
              fi
              ;;
              -S|–suspend)
              sudo pm-suspend
              echo ‘pm-suspend’ | at now + 360s
              ;;
              -r|–reboot)
              ___________________________________
              fi
              ;;
              -S|–suspend)
              sudo sleep 360s && pm-suspend
              ;;
              -r|–reboot)

              #11687
              Member
              fatmac
                Helpful
                Up
                0
                ::

                The only odd thing that I can see is ‘fi’ which normally means ‘finish’, perhaps it should be ‘if’.

                Linux (& BSD) since 1999

                #11692
                Member
                rej
                  Helpful
                  Up
                  0
                  ::

                  Xfce was removed via command line before installing LXDE – maybe left configuration?

                  This is the entire file prior to editing:
                  ____________________________________________-
                  #!/bin/bash
                  #exit antix bash backend
                  . /usr/local/lib/desktop-session/desktop-session-file-locations.sh

                  help() {
                  echo “Usage:”
                  echo “-l | –logout Logout of the current session”;
                  echo “-L | –lock Lock the current session”;
                  echo “-h | –hibernate Set the machine into hibernate”;
                  echo “-s | –shutdown Shutdown your machine”;
                  echo “-S | –suspend Set the machine into suspend”;
                  echo “-r | –reboot Reboot your machine”;
                  echo “-R | –restart Restart the session”;
                  }

                  case $1 in
                  -l|–logout)
                  $desktop_session_logout
                  ;;
                  -L|–lock)
                  xlock
                  ;;
                  h|–help)
                  help
                  ;;
                  #-H|–hibernate)
                  # sudo pm-hibernate
                  # ;;
                  -s|–shutdown)
                  if [ -e /etc/live/config/save-persist -o -e /live/config/persist-save.conf ] && which persist-config &> /dev/null; then
                  sudo persist-config –shutdown –command poweroff
                  else
                  sync
                  sudo chvt 1
                  sudo poweroff
                  fi
                  ;;
                  -S|–suspend)
                  sudo pm-suspend
                  ;;
                  -r|–reboot)
                  if [ -e /etc/live/config/save-persist -o -e /live/config/persist-save.conf ] && which persist-config &> /dev/null; then
                  sudo persist-config –shutdown –command reboot
                  else
                  sync
                  sudo chvt 1
                  sudo reboot
                  fi
                  ;;
                  -R|–Restart)
                  $desktop_session_restart
                  ;;
                  *)
                  if [ “$DISPLAY” ]; then
                  $desktop_session_exit_gui &
                  exit
                  else
                  echo “$1 Not an option”
                  help;
                  fi
                  ;;
                  esac

                  #11701
                  Moderator
                  BobC
                    Helpful
                    Up
                    0
                    ::

                    I’m no expert, but I don’t see anything wrong with the code above. I fixed the Hibernate to work on mine.

                    I forget if suspend needs a swap partition…

                    You could look in /var/log/pm-suspend.log for clues as to why suspend didn’t complete.

                    An idea would be to reconfigure or reinstall pm-utils

                    dpkg-reconfigure pm-utils

                    or if that doesn’t work

                    apt-get install –reinstall pm-utils

                    PS:Another package, the one that includes desktop-session-exit.py that calls desktop-session-exit is desktop-session-antix.
                    PSS: When i said the file looked ok, I was referring to the 2nd one that looked normal. Not sure what happened to the 1st one or what effects it would have.

                    • This reply was modified 4 years, 9 months ago by BobC.
                    • This reply was modified 4 years, 9 months ago by BobC.
                    #11708
                    Member
                    rej
                      Helpful
                      Up
                      0
                      ::

                      BobC-

                      Reinstalled AntiX w/ LXDE so that no previous configurations would interfere (such as ‘systemctl suspend’ or Xfce4 power mngr).
                      No success with attempts to resolve listed below. Although it would be nice to know why it doesn’t work, will just use Xfce4 Power Manager and be satisfied.

                      Thanks very much for your help – learned more useful information with every suggestion.

                      _________________________________________

                      re: /var/log/pm-suspend.log – no file before or after installations and editing.
                      re: /usr/share/doc/desktop-session-antix – contains only a copyright file. [pkg shown as installed in Synaptic]
                      ___________________________
                      ___________________________
                      command line fail:

                      root@antix17:/home/rj# apt-get install –reinstall pm-utils
                      Reading package lists… Done
                      Building dependency tree
                      Reading state information… Done
                      E: Unable to locate package –reinstall
                      ————————

                      root@antix17:/home/rj# apt-get install –pm-utils
                      Reading package lists… Done
                      Building dependency tree
                      Reading state information… Done
                      E: Unable to locate package –pm-utils
                      ___________________________
                      ___________________________
                      Successfully through Synaptic Pkg Mngr:

                      re-installed:

                      powermgmt-base

                      Common utils and configs for power management

                      —————-

                      installed:

                      pm-utils

                      utilities and scripts for power management
                      [confirmed in history log file and indicated as installed after]
                      ___________________________
                      ___________________________

                      No suspend after suffient time with each edit:
                      ———————–
                      fi
                      ;;
                      -S|–suspend)
                      sudo pm-suspend
                      echo ‘pm-suspend’ | at now + 360s
                      ;;
                      -r|–reboot)
                      ___________________________
                      fi
                      ;;
                      -S|–suspend)
                      sudo sleep 360s && pm-suspend
                      ;;
                      -r|–reboot)

                      ____________________________
                      fi
                      ;;
                      -S|–suspend)
                      sudo sleep 6s; sudo pm-suspend
                      ;;
                      -r|–reboot)

                      #11715
                      Moderator
                      BobC
                        Helpful
                        Up
                        0
                        ::

                        Sorry, I had copied the syntax for apt-get from a place that had it backwards and I didn’t notice and just changed the package name.

                        Based on your post though, I think you would be best to use synaptic, since that way you don’t have syntax difficulties to deal with.

                        You might also try having a “sandbox” system where you run from a fresh install and test changes one at a time before implementing them on your main system.

                        #11716
                        Moderator
                        BobC
                          Helpful
                          Up
                          0
                          ::

                          So I looked a little deeper and tried a few things. Maybe you didn’t try running the commands you expected to work from a terminal first?

                          1.) antix doesn’t include systemd. systemctl uses systemd. In the first post, some of those commands had systemctl in them, which makes me think you installed something that installed systemd. If you have added systemd to antix I really can’t help you because antix is what people like me run to avoid systemd, so it would be lucky if it ran at all, and I think it would likely be messed up and you would be best off to reinstall and start over.

                          Ok, if you didn’t install systemd and have pm-utils installed, here is how you could run from a terminal to test what command would be able to make the pc suspend…

                          Testing suspend:
                          2.) su to root and run pm-suspend, that works
                          bobc@hpdv9917d:~
                          $ su
                          Password:
                          root@hpdv9917d:/home/bobc# pm-suspend
                          root@hpdv9917d:/home/bobc#

                          3.) exit from root and try to run pm-suspend, it won’t run from a regular user unless you use sudo because it can’t find the command
                          root@hpdv9917d:/var/log# exit
                          exit

                          root@hpdv9917d:/home/bobc# exit
                          exit
                          bobc@hpdv9917d:~
                          $ pm-suspend
                          bash: pm-suspend: command not found
                          bobc@hpdv9917d:~

                          4.) run pm-suspend from regular user via sudo, that works
                          $ sudo pm-suspend
                          bobc@hpdv9917d:~

                          5.) run pm-suspend 3 minutes from now, won’t work because antix doesn’t include at command
                          $ echo ‘pm-suspend’ | at now + 3 minutes
                          bash: at: command not found
                          bobc@hpdv9917d:~
                          $

                          6.) sleep 30 seconds then run pm-suspend, won’t work because the sudo itself is trying to run in background, so never gets the password
                          bobc@hpdv9917d:~
                          $ sudo sleep 30 && pm-suspend &

                          7.) sleep 30 seconds then run pm-suspend but not in background, doesn’t work because pm-suspend needs authority
                          bobc@hpdv9917d:~
                          $ sudo sleep 30 && pm-suspend
                          bash: pm-suspend: command not found

                          8.) sleep 30 seconds then run pm-suspend but not in background, works with sudo authority
                          bobc@hpdv9917d:~
                          $ sudo sleep 30 && sudo pm-suspend
                          bobc@hpdv9917d:~
                          $

                          #11720
                          Member
                          rej
                            Helpful
                            Up
                            0
                            ::

                            I have not installed systemd – the ctl commands were found online, did not know they were systemd. Just a last ditch effort, while running out of options. On this install had not run those commands.

                            It only appears to suspend the one time – it does not suspend without using “sudo sleep 30 && sudo pm-suspend” again, after wake-up.

                            Editing the file in “/usr/local/bin/desktop-session-exit” as root and using that line in it doesn’t suspend, and using “sudo”, “su”, or neither one, in the edit, makes no difference.

                            The Logout GUI has suspend option and that works manually, however, sometimes I have 2 or more devices running, get distracted for awhile and need suspend to kick in automatically.

                            Is there a command that would hold the configuration so that the command line or “Logout GUI – Suspend” would not have to be used manually – auto-suspend after 20 minutes, the way Xfce Power Manager runs?
                            _______

                            I have posted 2 sets of the commands you gave me below. In the first, I totally overlooked # 2). In the second, I ran it first. The results appeared to be identical, except for the 6) [1] # – (process i.d.?)

                            In # 3), the terminal was closed by “x” at top right, without using the exit command – both sets.

                            Maybe I have overlooked an important step?

                            Thank you again.
                            ——————————————————
                            3)
                            rj@antix17.1rj:~
                            $ pm-suspend
                            This utility may only be run by the root user.
                            rj@antix17.1rj:~
                            $

                            4)
                            rj@antix17.1rj:~
                            $ pm-suspend
                            This utility may only be run by the root user.
                            rj@antix17.1rj:~
                            $ sudo pm-suspend
                            rj@antix17.1rj:~
                            $

                            5)
                            rj@antix17.1rj:~
                            $ sudo echo ‘pm-suspend’ | at now + 3 minutes
                            bash: at: command not found
                            [sudo] password for rj:

                            6)rj@antix17.1rj:~
                            $ sudo sleep 30 && pm-suspend &
                            [1] 6269 [???]
                            rj@antix17.1rj:~
                            $

                            7)rj@antix17.1rj:~
                            $ sudo sleep 30 && pm-suspend
                            This utility may only be run by the root user. [different result than yours]
                            rj@antix17.1rj:~

                            8)$ sudo sleep 30 && sudo pm-suspend
                            rj@antix17.1rj:~
                            $
                            ______________________________
                            ______________________________
                            2)
                            rj@antix17.1rj:~
                            $ su
                            Password:
                            root@antix17:/home/rj# pm-suspend

                            3)
                            rj@antix17.1rj:~
                            $ pm-suspend
                            This utility may only be run by the root user.
                            rj@antix17.1rj:~
                            $

                            4)
                            rj@antix17.1rj:~
                            $ sudo pm-suspend
                            rj@antix17.1rj:~
                            $

                            5)
                            $ echo ‘pm-suspend’ | at now + 3 minutes
                            bash: at: command not found
                            rj@antix17.1rj:~
                            $

                            6)
                            rj@antix17.1rj:~
                            $ sudo sleep 30 && pm-suspend &
                            [1] 7159
                            rj@antix17.1rj:~ [no suspend / 7159 – process i.d. #?]

                            7)
                            rj@antix17.1rj:~
                            $ sudo sleep 30 && pm-suspend
                            [sudo] password for rj:
                            This utility may only be run by the root user.
                            rj@antix17.1rj:~
                            $

                            8)
                            rj@antix17.1rj:~
                            $ sudo sleep 30 && sudo pm-suspend
                            rj@antix17.1rj:~
                            $

                            #11728
                            Moderator
                            BobC
                              Helpful
                              Up
                              0
                              ::

                              I understand now.

                              You want the system to suspend automatically after 30 minutes of inactivity?

                              https://unix.stackexchange.com/questions/227143/how-to-run-custom-script-as-screensaver-in-openbox

                              install xautolock via synaptic if not already installed

                              Somewhere in the startup scripts (not sure where), as root, run:

                              xautolock -time 30 -locker “pm-suspend”&

                              You could test it as root from a terminal (or run it from there every time you boot), and if it works, find out where to run it automatically. It did work on my system from the command line. I’m not sure where the best place is to run it automatically.

                              • This reply was modified 4 years, 9 months ago by BobC.
                              #11732
                              Member
                              rej
                                Helpful
                                Up
                                0
                                ::

                                This looks interesting – will see if it will work out. The activity-screenblanking options could be useful. If it doesn’t serve, back to Xfce Power Manager.

                                Thank you for your time and patience with this. All good information!

                                Going to look into the system “sandboxing” suggestion also. My browser is sandboxed 99.9% of time. The current arrangement is to load an extra hard drive for testing new configurations, desktops, etc. and if something could affect the next try, just reloading the snapshot for more testing with a clean USB copy. Tried “Timeshift” and had a major problem with the backup (more than likely operator-error…usually works just fine) Returned to using snaphots because it seems to be fail-proof.

                                Either way, I will consider this “solved”, although it can no longer be edited in the posting title.

                                Thanks again!

                                #11733
                                Moderator
                                Brian Masinick
                                  Helpful
                                  Up
                                  0
                                  ::

                                  Also keep in mind that for any system configuration where you are effectively performing a “snapshot”, saving the entire ” system context” it means that you need space large enough to save the entire operating system – the kernel, core utilities, and running processes. For suspend and hibernate to work properly, “swap” space MUST be AT LEAST twice the size of memory. If you have 16 GB memory, make your swap partition 32 GB.

                                  Note that if you don’t use hibernate or suspend and you have ample memory, these days you can actually get away with minimal, if any, swap space. Today’s swap is primarily used for suspend and hibernate system events.

                                  --
                                  Brian Masinick

                                Viewing 15 posts - 1 through 15 (of 26 total)
                                • You must be logged in to reply to this topic.