Poweroff after inactivity / a script?

Forum Forums General Software Poweroff after inactivity / a script?

  • This topic has 20 replies, 5 voices, and was last updated Oct 18-1:29 pm by augusteBurin.
Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #90234
    Member
    augusteBurin

      The suspend mode does not work on my old Dell740. I hope to find a way to make the pc power off after, let’s say 30 minutes doing nothing. Any ideas, a script maybe?
      Thanks for all help.
      Augusto on Antix21 iceWM

      • This topic was modified 1 year, 7 months ago by augusteBurin.
      #90286
      Member
      sybok

        1) How do you specify *doing nothing* (in terms of user input, internet activity, HDD/SDD activity, some program [not-]running)?
        E.g. what if a download/file-transfer is running (download using browser, curl/wget or via SSH) or an audio/visual file is being played.
        Does this count or not?

        2) Suspending not working:
        What does not work? I.e. what do you do, what do you expect and what do you get?

        Sometimes, I search for an issue using keywords describing the issue and adding ‘Debian’ or ‘Ubuntu’ since antiX, similarly to *buntu, is Debian based.
        Of course, not all the tips are applicable to antiX and, as always, to be used with great care.

        I got e.g. the following link
        http://askubuntu.com/questions/1117479/ubuntu-18-04-dell-xps-13-9350-suspend-issues-when-lid-closed
        ‘pm-utils’ and ‘lid’ may be packages to check for.

        3) Laptop battery usage may benefit from packages such as ‘tlp’ and ‘laptop-mode-tools’.
        Using one of them may have its downsides, I think the latter used to turn off some not used HW ports/”devices” causing wi-fi issues.

        PS: Could you please add a link to the French version (where you mention a script)?

        #90295
        Member
        Vincent17

          Hello,
          Maybe xprintidle would work. It returns milliseconds since the last mouse or keyboard activity. For example, I run this script at startup.

          while true; do
          	sleep 120
          	# don't shut down if cpu or sound active
          		awk '{if ($1>.5) exit 1}' /proc/loadavg || continue
          		grep -qr "RUNNING" /proc/asound/card* && continue
          	# don't shut down if less than 15 min since mouse/keyboard activity
          		[[ $(xprintidle) -lt 900000 ]] && continue
          	poweroff
          done

          Hope this helps.

          • This reply was modified 1 year, 7 months ago by Vincent17.
          • This reply was modified 1 year, 7 months ago by Vincent17. Reason: correction
          #90337
          Member
          augusteBurin

            Hello,
            By doing nothing I would be happy with just no keyboard or mouse activity, but of course a download check would be nice, but I guess I could manage that by stopping the script in the rare case of long downloads on this desktop, which is essentially for office use.

            Suspend through Antix menu ‘works’, but not the wake up , so it doesn’t work.

            In the french forum, there is discussion about things working on other debian based distros, but not on Antix.
            You can see her: https://www.antixforum.com/forums/topic/eteindre-lordi-apres-inactivite/

            so long!
            AB

            #90341
            Member
            augusteBurin

              Hello
              Sorry not to know how to use correctly the forum features, but this is answer to @vincent17 post
              I try :

              #! /bin/bash
              while true; do
              	sleep 120
              	# don't shut down if cpu or sound active
              		awk '{if ($1>.5) exit 1}' /proc/loadavg || continue
              		grep -qr "RUNNING" /proc/asound/card* && continue
              	# don't shut down if less than 1 min since mouse/keyboard activity
              		[[ $(xprintidle) -lt 60000 ]] && continue
                      echo "poweroff test"
              	#poweroff
              done

              I call it powrf.sh and do a chmod +x powrf.sh
              but when I test it in a terminal it outputs “ligne 8: xprintidle : commande introuvable” (no such command) repeated until I stop it.

              I am on Antix21 using iceWM
              Thanks for echoes.
              AB

              #90347
              Member
              sybok

                It seems that you do not have ‘xprintidle’ installed, try:
                sudo apt install xprintidle

                #90348
                Member
                augusteBurin

                  that works!
                  Now it would be perfect if it was a warning delay before the poweroff.

                  thanks.
                  ab

                  #90349
                  Member
                  sybok

                    Look up the forum for implementing emergency suspend/shutdown; the code/script there contains similar functionality.
                    https://www.antixforum.com/forums/topic/how-do-i-implement-an-automated-emergency-suspend-or-shutdown/

                    #90356
                    Member
                    Vincent17

                      a download check would be nice, but I guess I could manage that by stopping the script

                      I’ve never figured out a good way to do that, but in the script below, if you
                      do touch /tmp/no-suspend then it won’t poweroff; no need to stop the script. Do rm /tmp/no-suspend to allow poweroff again.

                      a warning delay before the poweroff

                      Also added below

                      #! /bin/bash
                      while true; do
                      	sleep 120
                      	# don't shut down if less than 15 min since mouse/keyboard activity
                      	        [[ $(xprintidle) -lt 900000 ]] && continue
                              # don't shut down if /tmp/no-suspend exists 
                                      [[ -f /tmp/no-suspend ]] && continue
                              # don't shut down if cpu or sound active
                      		awk '{if ($1>.5) exit 1}' /proc/loadavg || continue
                      		grep -qr "RUNNING" /proc/asound/card* && continue
                      	yad --on-top --text "SHUT DOWN" --timeout 4 --timeout-indicator=top --button "Cancel" || poweroff
                      done
                      • This reply was modified 1 year, 7 months ago by Vincent17.
                      • This reply was modified 1 year, 7 months ago by Vincent17. Reason: for clarity
                      • This reply was modified 1 year, 7 months ago by Vincent17.
                      #90359
                      Moderator
                      BobC

                        CLICK IT QUICK!!!!

                        Daily driver distro https://www.antixforum.com

                        #90362
                        Member
                        blur13

                          Haha you better have quick reactions. And pray you’re not in the kitchen getting a glass of water.

                          #90376
                          Member
                          augusteBurin

                            This is great!
                            But please: why sleep? and why 120 ?
                            And timeout 4, is that milliseconds, minutes, hours, days?

                            AB

                            • This reply was modified 1 year, 7 months ago by augusteBurin.
                            #90378
                            Member
                            blur13

                              sleep 120 is used to execute the script every two minutes. Timeout 4 is in seconds.

                              #90382
                              Member
                              Vincent17

                                More details: As written, the script checks computer activity every 120 seconds; the keyboard/mouse idle time to trigger shutdown is 900000 milliseconds; shutdown is prevented if 1-minute cpu load average is over 0.5; the warning delay before poweroff is [only!] 4 seconds. Of course, all of these can be changed to meet your needs.
                                I’m glad you’ve found it useful.

                                #90410
                                Member
                                sybok

                                  When in doubt, you can also explore the man-pages of the command:
                                  man sleep

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