How do I detect when the system suspends?












6














I need to be able to log the times that an Ubuntu 10.04 Desktop system is suspended and resumed.



I can detect when the system is resumed via a DBus signal (org.freedesktop.UPower.Resuming()) but the corresponding "org.freedesktop.UPower.Sleeping()" signal is never fired. Ideally, I'd like to use DBus, but given the lack of success I'm having, I'd be happy with any solution providing it can be called from the command line.



I've discovered one way to do it:



tail -f /var/log/pm-suspend.log | grep "performing suspend"



This simply listens on one of the pm logs for the suspend logging. Although this works, it's probably rather brittle. I've found relying on log parsing to be rather problematic in the past due to changes in the log statements.



Ideally I'd like a more robust mechanism. The service that invokes this will be ran as root.










share|improve this question





























    6














    I need to be able to log the times that an Ubuntu 10.04 Desktop system is suspended and resumed.



    I can detect when the system is resumed via a DBus signal (org.freedesktop.UPower.Resuming()) but the corresponding "org.freedesktop.UPower.Sleeping()" signal is never fired. Ideally, I'd like to use DBus, but given the lack of success I'm having, I'd be happy with any solution providing it can be called from the command line.



    I've discovered one way to do it:



    tail -f /var/log/pm-suspend.log | grep "performing suspend"



    This simply listens on one of the pm logs for the suspend logging. Although this works, it's probably rather brittle. I've found relying on log parsing to be rather problematic in the past due to changes in the log statements.



    Ideally I'd like a more robust mechanism. The service that invokes this will be ran as root.










    share|improve this question



























      6












      6








      6


      3





      I need to be able to log the times that an Ubuntu 10.04 Desktop system is suspended and resumed.



      I can detect when the system is resumed via a DBus signal (org.freedesktop.UPower.Resuming()) but the corresponding "org.freedesktop.UPower.Sleeping()" signal is never fired. Ideally, I'd like to use DBus, but given the lack of success I'm having, I'd be happy with any solution providing it can be called from the command line.



      I've discovered one way to do it:



      tail -f /var/log/pm-suspend.log | grep "performing suspend"



      This simply listens on one of the pm logs for the suspend logging. Although this works, it's probably rather brittle. I've found relying on log parsing to be rather problematic in the past due to changes in the log statements.



      Ideally I'd like a more robust mechanism. The service that invokes this will be ran as root.










      share|improve this question















      I need to be able to log the times that an Ubuntu 10.04 Desktop system is suspended and resumed.



      I can detect when the system is resumed via a DBus signal (org.freedesktop.UPower.Resuming()) but the corresponding "org.freedesktop.UPower.Sleeping()" signal is never fired. Ideally, I'd like to use DBus, but given the lack of success I'm having, I'd be happy with any solution providing it can be called from the command line.



      I've discovered one way to do it:



      tail -f /var/log/pm-suspend.log | grep "performing suspend"



      This simply listens on one of the pm logs for the suspend logging. Although this works, it's probably rather brittle. I've found relying on log parsing to be rather problematic in the past due to changes in the log statements.



      Ideally I'd like a more robust mechanism. The service that invokes this will be ran as root.







      suspend suspend-resume






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 18 '10 at 15:02

























      asked Oct 18 '10 at 13:42









      Paul Robinson

      334




      334






















          3 Answers
          3






          active

          oldest

          votes


















          7














          Try putting the following in /etc/pm/sleep.d. This should be independent of whether your machine uses APM or ACPI.



          #!/bin/sh

          LOGFILE="/var/log/sleep.log"

          case "$1" in
          resume)
          echo "Resumed from suspend at `date`" >> "$LOGFILE"
          ;;
          thaw)
          echo "Resumed from hibernation at `date`" >> "$LOGFILE"
          ;;
          suspend)
          echo "Suspended to ram at `date`" >> "$LOGFILE"
          ;;
          hibernate)
          echo "Hibernated to disk at `date`" >> "$LOGFILE"
          ;;
          esac





          share|improve this answer





























            1














            You can drop a script in /etc/apm/suspend.d. It should be executed every time the machine suspends.



            You can also use /etc/apm/resume.d in a similar fashion to run a script when it wakes up.






            share|improve this answer





















            • Thanks for the answer, It seems like I don't have apm support in my kernel. I see "No APM support in kernel" when i run the command "apm". I know that I can enable this in the kernel for my machine. However, I need to run my program on other machines on which I won't be able to make this change so I don't think APM is going to work :-(
              – Paul Robinson
              Oct 18 '10 at 14:50



















            0














            A few other options that may work on more modern systems are:



            cat /var/log/syslog | grep 'systemd-sleep' which will display system suspensions and resumes with timestamps.



            or



            journalctl | grep suspend which will display also display suspensions and resumes with timestamps. The suspends here will look something like PM: suspend entry (s2idle) and the resumes will look like suspend exit.






            share|improve this answer





















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "89"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f8112%2fhow-do-i-detect-when-the-system-suspends%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              7














              Try putting the following in /etc/pm/sleep.d. This should be independent of whether your machine uses APM or ACPI.



              #!/bin/sh

              LOGFILE="/var/log/sleep.log"

              case "$1" in
              resume)
              echo "Resumed from suspend at `date`" >> "$LOGFILE"
              ;;
              thaw)
              echo "Resumed from hibernation at `date`" >> "$LOGFILE"
              ;;
              suspend)
              echo "Suspended to ram at `date`" >> "$LOGFILE"
              ;;
              hibernate)
              echo "Hibernated to disk at `date`" >> "$LOGFILE"
              ;;
              esac





              share|improve this answer


























                7














                Try putting the following in /etc/pm/sleep.d. This should be independent of whether your machine uses APM or ACPI.



                #!/bin/sh

                LOGFILE="/var/log/sleep.log"

                case "$1" in
                resume)
                echo "Resumed from suspend at `date`" >> "$LOGFILE"
                ;;
                thaw)
                echo "Resumed from hibernation at `date`" >> "$LOGFILE"
                ;;
                suspend)
                echo "Suspended to ram at `date`" >> "$LOGFILE"
                ;;
                hibernate)
                echo "Hibernated to disk at `date`" >> "$LOGFILE"
                ;;
                esac





                share|improve this answer
























                  7












                  7








                  7






                  Try putting the following in /etc/pm/sleep.d. This should be independent of whether your machine uses APM or ACPI.



                  #!/bin/sh

                  LOGFILE="/var/log/sleep.log"

                  case "$1" in
                  resume)
                  echo "Resumed from suspend at `date`" >> "$LOGFILE"
                  ;;
                  thaw)
                  echo "Resumed from hibernation at `date`" >> "$LOGFILE"
                  ;;
                  suspend)
                  echo "Suspended to ram at `date`" >> "$LOGFILE"
                  ;;
                  hibernate)
                  echo "Hibernated to disk at `date`" >> "$LOGFILE"
                  ;;
                  esac





                  share|improve this answer












                  Try putting the following in /etc/pm/sleep.d. This should be independent of whether your machine uses APM or ACPI.



                  #!/bin/sh

                  LOGFILE="/var/log/sleep.log"

                  case "$1" in
                  resume)
                  echo "Resumed from suspend at `date`" >> "$LOGFILE"
                  ;;
                  thaw)
                  echo "Resumed from hibernation at `date`" >> "$LOGFILE"
                  ;;
                  suspend)
                  echo "Suspended to ram at `date`" >> "$LOGFILE"
                  ;;
                  hibernate)
                  echo "Hibernated to disk at `date`" >> "$LOGFILE"
                  ;;
                  esac






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 18 '10 at 15:22









                  Ryan Thompson

                  2,71332134




                  2,71332134

























                      1














                      You can drop a script in /etc/apm/suspend.d. It should be executed every time the machine suspends.



                      You can also use /etc/apm/resume.d in a similar fashion to run a script when it wakes up.






                      share|improve this answer





















                      • Thanks for the answer, It seems like I don't have apm support in my kernel. I see "No APM support in kernel" when i run the command "apm". I know that I can enable this in the kernel for my machine. However, I need to run my program on other machines on which I won't be able to make this change so I don't think APM is going to work :-(
                        – Paul Robinson
                        Oct 18 '10 at 14:50
















                      1














                      You can drop a script in /etc/apm/suspend.d. It should be executed every time the machine suspends.



                      You can also use /etc/apm/resume.d in a similar fashion to run a script when it wakes up.






                      share|improve this answer





















                      • Thanks for the answer, It seems like I don't have apm support in my kernel. I see "No APM support in kernel" when i run the command "apm". I know that I can enable this in the kernel for my machine. However, I need to run my program on other machines on which I won't be able to make this change so I don't think APM is going to work :-(
                        – Paul Robinson
                        Oct 18 '10 at 14:50














                      1












                      1








                      1






                      You can drop a script in /etc/apm/suspend.d. It should be executed every time the machine suspends.



                      You can also use /etc/apm/resume.d in a similar fashion to run a script when it wakes up.






                      share|improve this answer












                      You can drop a script in /etc/apm/suspend.d. It should be executed every time the machine suspends.



                      You can also use /etc/apm/resume.d in a similar fashion to run a script when it wakes up.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Oct 18 '10 at 13:48









                      Javier Rivera

                      29.8k977101




                      29.8k977101












                      • Thanks for the answer, It seems like I don't have apm support in my kernel. I see "No APM support in kernel" when i run the command "apm". I know that I can enable this in the kernel for my machine. However, I need to run my program on other machines on which I won't be able to make this change so I don't think APM is going to work :-(
                        – Paul Robinson
                        Oct 18 '10 at 14:50


















                      • Thanks for the answer, It seems like I don't have apm support in my kernel. I see "No APM support in kernel" when i run the command "apm". I know that I can enable this in the kernel for my machine. However, I need to run my program on other machines on which I won't be able to make this change so I don't think APM is going to work :-(
                        – Paul Robinson
                        Oct 18 '10 at 14:50
















                      Thanks for the answer, It seems like I don't have apm support in my kernel. I see "No APM support in kernel" when i run the command "apm". I know that I can enable this in the kernel for my machine. However, I need to run my program on other machines on which I won't be able to make this change so I don't think APM is going to work :-(
                      – Paul Robinson
                      Oct 18 '10 at 14:50




                      Thanks for the answer, It seems like I don't have apm support in my kernel. I see "No APM support in kernel" when i run the command "apm". I know that I can enable this in the kernel for my machine. However, I need to run my program on other machines on which I won't be able to make this change so I don't think APM is going to work :-(
                      – Paul Robinson
                      Oct 18 '10 at 14:50











                      0














                      A few other options that may work on more modern systems are:



                      cat /var/log/syslog | grep 'systemd-sleep' which will display system suspensions and resumes with timestamps.



                      or



                      journalctl | grep suspend which will display also display suspensions and resumes with timestamps. The suspends here will look something like PM: suspend entry (s2idle) and the resumes will look like suspend exit.






                      share|improve this answer


























                        0














                        A few other options that may work on more modern systems are:



                        cat /var/log/syslog | grep 'systemd-sleep' which will display system suspensions and resumes with timestamps.



                        or



                        journalctl | grep suspend which will display also display suspensions and resumes with timestamps. The suspends here will look something like PM: suspend entry (s2idle) and the resumes will look like suspend exit.






                        share|improve this answer
























                          0












                          0








                          0






                          A few other options that may work on more modern systems are:



                          cat /var/log/syslog | grep 'systemd-sleep' which will display system suspensions and resumes with timestamps.



                          or



                          journalctl | grep suspend which will display also display suspensions and resumes with timestamps. The suspends here will look something like PM: suspend entry (s2idle) and the resumes will look like suspend exit.






                          share|improve this answer












                          A few other options that may work on more modern systems are:



                          cat /var/log/syslog | grep 'systemd-sleep' which will display system suspensions and resumes with timestamps.



                          or



                          journalctl | grep suspend which will display also display suspensions and resumes with timestamps. The suspends here will look something like PM: suspend entry (s2idle) and the resumes will look like suspend exit.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 23 '18 at 7:23









                          Gregory Arenius

                          1012




                          1012






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Ask Ubuntu!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f8112%2fhow-do-i-detect-when-the-system-suspends%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                              Mangá

                               ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕