bash script won’t start at boot

Forum Forums Official Releases antiX-21/22 “Grup Yorum” bash script won’t start at boot

  • This topic has 14 replies, 5 voices, and was last updated Feb 15-9:31 pm by sbis.
Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #73978
    Member
    sbis

      Hi, I have a problem.
      The monitor randomly shutdown.

      After a quick search in the web I found a possible solution.
      Run this command:
      $ xset dpms 0 0 0 && xset -dpms && xset s off && xset s noblank

      This change the result of the command “$ xset q” from this:

      DPMS (Energy Star):
      Standby: 3600 Suspend: 3600 Off: 3600
      DPMS is Enabled
      Monitor is On

      to this:
      ….
      DPMS (Energy Star):
      Standby: 0 Suspend: 0 Off: 0
      DPMS is Disabled

      I don’t know if this solution is the best but I have tested for a while and at the moment the monitor is still on. 😀

      I want to start the command at boot so I have create a simple bash script named noblank_monitor.sh:
      #!/bin/bash
      xset dpms 0 0 0 && xset -dpms && xset s off && xset s noblank

      I simply put the line (~/./noblank_monitor.sh &) in ~/.icewm/startup and in ~/.desktop-session/startup but when the pc boot the command “$ xset q” always show this:

      DPMS (Energy Star):
      Standby: 3600 Suspend: 3600 Off: 3600
      DPMS is Enabled
      Monitor is On

      I have tested another simple script, clock.sh:
      #!/bin/bash
      date >> ~/clock.txt
      and it work if I put the line ~/./clock.sh &) in ~/.icewm/startup.

      What’s wrong?

      Thanks

      #73979
      Moderator
      caprea
        Helpful
        Up
        0
        ::

        It might helps troubleshooting if you start your script from terminal with ~/./noblank_monitor.sh &
        Is the script executable?

        #73980
        Anonymous
          Helpful
          Up
          0
          ::

          xset dpms 0 0 0 && xset -dpms && xset s off && xset s noblank &

          append an ampersand character to the newly added line within the startup file, then retry

          #73987
          Member
          sbis
            Helpful
            Up
            0
            ::

            It might helps troubleshooting if you start your script from terminal with ~/./noblank_monitor.sh &
            Is the script executable?

            yes, the script is executable and work fine from terminal

            • This reply was modified 1 year, 4 months ago by sbis.
            #73989
            Member
            sbis
              Helpful
              Up
              0
              ::

              xset dpms 0 0 0 && xset -dpms && xset s off && xset s noblank &

              append an ampersand character to the newly added line within the startup file, then retry

              No, nothing change with & at the end

              #73994
              Moderator
              caprea
                Helpful
                Up
                0
                ::

                I just tried your script and it works here on startup.No problems.
                The script is in home and the line ~/./noblank_monitor.sh &
                is in /home/user/.desktop-session/startup

                #73996
                Member
                sbis
                  Helpful
                  Up
                  0
                  ::

                  I just tried your script and it works here on startup.No problems.
                  The script is in home and the line ~/./noblank_monitor.sh &
                  is in /home/user/.desktop-session/startup

                  I had take a look again in my /home/user/.desktop-session/startup to control what I wrote.
                  That’s ok but if I restart session or if I reboot “xset q” don’t change.

                  I see always:

                  DPMS (Energy Star):
                  Standby: 3600 Suspend: 3600 Off: 3600
                  DPMS is Enabled
                  Monitor is On

                  There’s a way to know if the script had been executed?

                  Thanks

                  #73997
                  Moderator
                  caprea
                    Helpful
                    Up
                    0
                    ::

                    These are the last lines of the xset q command output after rebooting here
                    DPMS (Energy Star):
                    Standby: 0 Suspend: 0 Off: 0
                    DPMS is Disabled

                    So the script is running.

                    Edit: Strange problem. The only thing I could think of is a time problem on your side.Maybe try a sleep addition like
                    sleep 4 ; ~/./noblank_monitor.sh &

                    • This reply was modified 1 year, 4 months ago by caprea.
                    #74001
                    Forum Admin
                    Dave
                      Helpful
                      Up
                      1
                      ::

                      Maybe use set-screen-blank (from the control centre, menu, or termianl) to turn off the screen blanking… In the control centre it is under the session tab.
                      The command you are trying to setup in a startup script is the exact same command used when turning off screen blanking with set-screen-blank.

                      On top of this, the set-screen-blank program also changes the variable SCREEN_BLANK_TIME= to 0 in ~/.desktop-session/desktop-session.conf.

                      Screen blanking time is set on startup in desktop-session after the startup file is run, which is likely why your command in startup is “not working”

                      • This reply was modified 1 year, 4 months ago by Dave.

                      Computers are like air conditioners. They work fine until you start opening Windows. ~Author Unknown

                      #74024
                      Member
                      sybok
                        Helpful
                        Up
                        1
                        ::

                        Hi,

                        not quite sure if you find it helpful:

                        1) Question:
                        1.A) Did you suspend/hibernate the PC after the login?
                        1.B) If it is a notebook/netbook etc., is some power-saving utility installed and active?
                        I guess it could override your setting.
                        Then 4) would be a good solution.
                        1.C) Did you check all cables connecting your monitor to PC and power, to be sure they are not loosely connected?

                        2) Test if the script did run

                        #!/bin/bash
                        xset dpms 0 0 0 && xset -dpms && xset s off && xset s noblank
                        touch /tmp/run.did

                        The added creates file ‘/tmp/run.did’ if it did not exist or it updates its modification time to current date.
                        I guess that the files in ‘/tmp/’ do not survive reboot/shutdown, thus a different way may achieve this.

                        3) Execution in startup-file(s):
                        sleep 4; bash <full|relative-path-name>
                        I prefer the more explicit call (that works even if the file is not executable or it is located in a partition mounted without ‘exec’ attribute).

                        4) How about a “service”?
                        This is a crude way as it would eat up resources; script with a loop:
                        – check if the setting is as desired
                        – if not, run the script to (un)set the blanking
                        – sleep

                        #!/bin/bash
                        while true; do
                          # Grep the line of interest, print the 3rd column 'Disabled|Enabled' and test the value:
                          current_setting="$(xset q | grep '^[ ]*DPMS is ' | awk ' { print $3 } ' | xargs)"
                          if [[ "${current_setting}" =~ ^Enabled$ ]]; then
                            bash <scriptname>
                            echo "$(date)" >> /tmp/run.did
                          fi
                          sleep 60 # Sleep 60 seconds
                        done

                        And start the service in your startup file instead
                        bash <service-script> &

                        Storing the time(s) when the script was called may help you to find out (possibly by checking logs in ‘/var/log/’) what could reset the blanking.

                        Comment:
                        I once tried to use ‘<command 1> && <command 2> &’ and it did not work well.
                        Thus I find the call ‘bash <scriptname> &’ as a better way to do it.

                        EDIT/Disclaimer: The script with loop is not an actual service, but I did dare to call it that way since it was inspired by the intention of starting it at boot.

                        • This reply was modified 1 year, 4 months ago by sybok. Reason: Added 1.C); improved the service-script and related comment
                        • This reply was modified 1 year, 4 months ago by sybok.
                        #74037
                        Member
                        sbis
                          Helpful
                          Up
                          0
                          ::

                          Hi,
                          not quite sure if you find it helpful:

                          1) Question:
                          1.A) Did you suspend/hibernate the PC after the login?
                          1.B) If it is a notebook/netbook etc., is some power-saving utility installed and active?
                          I guess it could override your setting.
                          Then 4) would be a good solution.
                          1.C) Did you check all cables connecting your monitor to PC and power, to be sure they are not loosely connected?

                          1.A) No, I didn’t.
                          1.B) My PC isn’t a notebook/netbook.
                          1.C) All it’s ok

                          2) Test if the script did run

                          #!/bin/bash
                          xset dpms 0 0 0 && xset -dpms && xset s off && xset s noblank
                          touch /tmp/run.did

                          The added creates file ‘/tmp/run.did’ if it did not exist or it updates its modification time to current date.
                          I guess that the files in ‘/tmp/’ do not survive reboot/shutdown, thus a different way may achieve this.

                          Thanks, I’ll use this tip in the future.

                          3) Execution in startup-file(s):
                          sleep 4; bash <full|relative-path-name>
                          I prefer the more explicit call (that works even if the file is not executable or it is located in a partition mounted without ‘exec’ attribute).

                          For now I follow the Dave’s hint.
                          If the problem persist I try yours.

                          4) How about a “service”?
                          This is a crude way as it would eat up resources; script with a loop:
                          – check if the setting is as desired
                          – if not, run the script to (un)set the blanking
                          – sleep

                          #!/bin/bash
                          while true; do
                            # Grep the line of interest, print the 3rd column 'Disabled|Enabled' and test the value:
                            current_setting="$(xset q | grep '^[ ]*DPMS is ' | awk ' { print $3 } ' | xargs)"
                            if [[ "${current_setting}" =~ ^Enabled$ ]]; then
                              bash <scriptname>
                              echo "$(date)" >> /tmp/run.did
                            fi
                            sleep 60 # Sleep 60 seconds
                          done

                          And start the service in your startup file instead
                          bash <service-script> &

                          Storing the time(s) when the script was called may help you to find out (possibly by checking logs in ‘/var/log/’) what could reset the blanking.

                          Comment:
                          I once tried to use ‘<command 1> && <command 2> &’ and it did not work well.
                          Thus I find the call ‘bash <scriptname> &’ as a better way to do it.

                          Thanks

                          #74038
                          Member
                          sbis
                            Helpful
                            Up
                            0
                            ::

                            3) Execution in startup-file(s):
                            sleep 4; bash <full|relative-path-name>
                            I prefer the more explicit call (that works even if the file is not executable or it is located in a partition mounted without ‘exec’ attribute).

                            Comment:
                            I once tried to use ‘<command 1> && <command 2> &’ and it did not work well.
                            Thus I find the call ‘bash <scriptname> &’ as a better way to do it.

                            For testing I add in my /home/user/.desktop-session/startup
                            sleep 5; bash ~/./noblank_monitor.sh &

                            and it work fine now.

                            #74040
                            Forum Admin
                            Dave
                              Helpful
                              Up
                              0
                              ::

                              Does the control centre program (set-screen-blank) not work / does it have a bug?

                              Computers are like air conditioners. They work fine until you start opening Windows. ~Author Unknown

                              #74042
                              Member
                              sbis
                                Helpful
                                Up
                                0
                                ::

                                Does the control centre program (set-screen-blank) not work / does it have a bug?

                                I don’t know.
                                I put the bash script apart.
                                For now I try (set-screen-blank) and in the next days I see what happen.

                                #77480
                                Member
                                sbis
                                  Helpful
                                  Up
                                  0
                                  ::

                                  Hi,
                                  in two months with “set-screen-blank” option enabled, the monitor has never turned off.

                                  Thank’s all

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