Cronjob - Script not running on reboot












0















I need to execute a script, myscript.sh, at every reboot.
After crontab -e I wrote:



@reboot /home/techy/Documents/myscript.sh


The file is executable after chmod 777 myscript.sh, but I'm not able to get output from shell script.



My shell script is supposed to change the desktop background, and is working if executed from terminal.










share|improve this question





























    0















    I need to execute a script, myscript.sh, at every reboot.
    After crontab -e I wrote:



    @reboot /home/techy/Documents/myscript.sh


    The file is executable after chmod 777 myscript.sh, but I'm not able to get output from shell script.



    My shell script is supposed to change the desktop background, and is working if executed from terminal.










    share|improve this question



























      0












      0








      0








      I need to execute a script, myscript.sh, at every reboot.
      After crontab -e I wrote:



      @reboot /home/techy/Documents/myscript.sh


      The file is executable after chmod 777 myscript.sh, but I'm not able to get output from shell script.



      My shell script is supposed to change the desktop background, and is working if executed from terminal.










      share|improve this question
















      I need to execute a script, myscript.sh, at every reboot.
      After crontab -e I wrote:



      @reboot /home/techy/Documents/myscript.sh


      The file is executable after chmod 777 myscript.sh, but I'm not able to get output from shell script.



      My shell script is supposed to change the desktop background, and is working if executed from terminal.







      cron






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 21 '16 at 22:43









      IanC

      671615




      671615










      asked Dec 21 '16 at 22:07









      techytechy

      3218




      3218






















          5 Answers
          5






          active

          oldest

          votes


















          1














          You cannot do this with @reboot, (or even cron). When your @reboot script runs, you haven't logged in (myscript.sh is run as root), the X Server hasn't been started, and the background you want to change doesn't even exist.



          I suggest using ~/.config/autostart/. The files there are .desktop files, see man desktop-file-validate, man desktop-file-edit, man desktop-file-install, ... . Since the files in my ~/.config/autostart/ put icons on the top of my screen, I think it's the right context/time to "change the desktop background".






          share|improve this answer
























          • can you please elaborate ? where should I put my script to execute at every reboot ?

            – techy
            Dec 22 '16 at 15:22



















          0














          You want to execute your script at logon, not at boot.

          as mentioned, a good way is to put a launcher (.desktop file) in the autostart folder
          ~/.config/autostart/


          More information about Gnome Autostart:
          Desktop Application Autostart Specification



          -1- Create the launcher:

          Copy/paste those lines in a terminal



          tee -a  ~/.config/autostart/myscript.desktop << END1
          #!/usr/bin/env xdg-open
          [Desktop Entry]
          Version=1.0
          Type=Application
          Terminal=false
          Exec='/home/techy/Documents/myscript.sh'
          Name=myscript
          END1
          chmod +x ~/.config/autostart/myscript.desktop


          -2- Start the launcher for the first time, it will ask you to validate

          Browse with file manager to ~/.config/autostart/

          Double-click on the new created myscript.desktop file

          Validate the security message popup

          -3- Done, test it

          Log-off then log in back in to see it working






          share|improve this answer

































            0














            Not sure about the details of your script in myscript.sh.



            If your script requires to connect remote host, then you need internet connection in the first place before execution of this script.



            To solve this, you need to put some delay (Example: sleep 5m) inside your script until internet connection is established successfully.



            This method solves my problem, but not sure if this works for you too.






            share|improve this answer








            New contributor




            Jerry Chong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.




























              -1














              I would try this instead.



              @reboot sleep 45 && sh /home/techy/Documents/myscript.sh


              That gives some time to your boot up, and the sh actually calls the shell script.
              You might need to run chmod -x /home/techy/Documents/myscript.sh this takes restrictions off of the script and path.






              share|improve this answer
























              • this does not answer the question

                – cmak.fr
                Jun 16 '18 at 23:28



















              -1














              I've been running into this problem on every boot. Ubuntu wasn't fully loading two hard drivers on my pc. I had to click on them at Nautilus in order to really load the drivers. I noticed that when running Transmission on startup using those drivers as a target for torrent files and it wasn't working.



              So I had to make this crontab magic and realized that the two commands below are very different indeed:



              crontab -e

              sudo crontab -e


              As I had to use root user's credentials to load the drivers only the second option worked for me and inside crontab file I could write



              @reboot /folder/loadhd.sh


              Check this:
              https://stackoverflow.com/questions/43237488/linux-difference-between-sudo-crontab-e-and-just-crontab-e






              share|improve this answer


























              • this does not answer the question

                – cmak.fr
                Jun 16 '18 at 23:28











              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%2f863240%2fcronjob-script-not-running-on-reboot%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              5 Answers
              5






              active

              oldest

              votes








              5 Answers
              5






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              You cannot do this with @reboot, (or even cron). When your @reboot script runs, you haven't logged in (myscript.sh is run as root), the X Server hasn't been started, and the background you want to change doesn't even exist.



              I suggest using ~/.config/autostart/. The files there are .desktop files, see man desktop-file-validate, man desktop-file-edit, man desktop-file-install, ... . Since the files in my ~/.config/autostart/ put icons on the top of my screen, I think it's the right context/time to "change the desktop background".






              share|improve this answer
























              • can you please elaborate ? where should I put my script to execute at every reboot ?

                – techy
                Dec 22 '16 at 15:22
















              1














              You cannot do this with @reboot, (or even cron). When your @reboot script runs, you haven't logged in (myscript.sh is run as root), the X Server hasn't been started, and the background you want to change doesn't even exist.



              I suggest using ~/.config/autostart/. The files there are .desktop files, see man desktop-file-validate, man desktop-file-edit, man desktop-file-install, ... . Since the files in my ~/.config/autostart/ put icons on the top of my screen, I think it's the right context/time to "change the desktop background".






              share|improve this answer
























              • can you please elaborate ? where should I put my script to execute at every reboot ?

                – techy
                Dec 22 '16 at 15:22














              1












              1








              1







              You cannot do this with @reboot, (or even cron). When your @reboot script runs, you haven't logged in (myscript.sh is run as root), the X Server hasn't been started, and the background you want to change doesn't even exist.



              I suggest using ~/.config/autostart/. The files there are .desktop files, see man desktop-file-validate, man desktop-file-edit, man desktop-file-install, ... . Since the files in my ~/.config/autostart/ put icons on the top of my screen, I think it's the right context/time to "change the desktop background".






              share|improve this answer













              You cannot do this with @reboot, (or even cron). When your @reboot script runs, you haven't logged in (myscript.sh is run as root), the X Server hasn't been started, and the background you want to change doesn't even exist.



              I suggest using ~/.config/autostart/. The files there are .desktop files, see man desktop-file-validate, man desktop-file-edit, man desktop-file-install, ... . Since the files in my ~/.config/autostart/ put icons on the top of my screen, I think it's the right context/time to "change the desktop background".







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Dec 21 '16 at 23:33









              waltinatorwaltinator

              22.6k74169




              22.6k74169













              • can you please elaborate ? where should I put my script to execute at every reboot ?

                – techy
                Dec 22 '16 at 15:22



















              • can you please elaborate ? where should I put my script to execute at every reboot ?

                – techy
                Dec 22 '16 at 15:22

















              can you please elaborate ? where should I put my script to execute at every reboot ?

              – techy
              Dec 22 '16 at 15:22





              can you please elaborate ? where should I put my script to execute at every reboot ?

              – techy
              Dec 22 '16 at 15:22













              0














              You want to execute your script at logon, not at boot.

              as mentioned, a good way is to put a launcher (.desktop file) in the autostart folder
              ~/.config/autostart/


              More information about Gnome Autostart:
              Desktop Application Autostart Specification



              -1- Create the launcher:

              Copy/paste those lines in a terminal



              tee -a  ~/.config/autostart/myscript.desktop << END1
              #!/usr/bin/env xdg-open
              [Desktop Entry]
              Version=1.0
              Type=Application
              Terminal=false
              Exec='/home/techy/Documents/myscript.sh'
              Name=myscript
              END1
              chmod +x ~/.config/autostart/myscript.desktop


              -2- Start the launcher for the first time, it will ask you to validate

              Browse with file manager to ~/.config/autostart/

              Double-click on the new created myscript.desktop file

              Validate the security message popup

              -3- Done, test it

              Log-off then log in back in to see it working






              share|improve this answer






























                0














                You want to execute your script at logon, not at boot.

                as mentioned, a good way is to put a launcher (.desktop file) in the autostart folder
                ~/.config/autostart/


                More information about Gnome Autostart:
                Desktop Application Autostart Specification



                -1- Create the launcher:

                Copy/paste those lines in a terminal



                tee -a  ~/.config/autostart/myscript.desktop << END1
                #!/usr/bin/env xdg-open
                [Desktop Entry]
                Version=1.0
                Type=Application
                Terminal=false
                Exec='/home/techy/Documents/myscript.sh'
                Name=myscript
                END1
                chmod +x ~/.config/autostart/myscript.desktop


                -2- Start the launcher for the first time, it will ask you to validate

                Browse with file manager to ~/.config/autostart/

                Double-click on the new created myscript.desktop file

                Validate the security message popup

                -3- Done, test it

                Log-off then log in back in to see it working






                share|improve this answer




























                  0












                  0








                  0







                  You want to execute your script at logon, not at boot.

                  as mentioned, a good way is to put a launcher (.desktop file) in the autostart folder
                  ~/.config/autostart/


                  More information about Gnome Autostart:
                  Desktop Application Autostart Specification



                  -1- Create the launcher:

                  Copy/paste those lines in a terminal



                  tee -a  ~/.config/autostart/myscript.desktop << END1
                  #!/usr/bin/env xdg-open
                  [Desktop Entry]
                  Version=1.0
                  Type=Application
                  Terminal=false
                  Exec='/home/techy/Documents/myscript.sh'
                  Name=myscript
                  END1
                  chmod +x ~/.config/autostart/myscript.desktop


                  -2- Start the launcher for the first time, it will ask you to validate

                  Browse with file manager to ~/.config/autostart/

                  Double-click on the new created myscript.desktop file

                  Validate the security message popup

                  -3- Done, test it

                  Log-off then log in back in to see it working






                  share|improve this answer















                  You want to execute your script at logon, not at boot.

                  as mentioned, a good way is to put a launcher (.desktop file) in the autostart folder
                  ~/.config/autostart/


                  More information about Gnome Autostart:
                  Desktop Application Autostart Specification



                  -1- Create the launcher:

                  Copy/paste those lines in a terminal



                  tee -a  ~/.config/autostart/myscript.desktop << END1
                  #!/usr/bin/env xdg-open
                  [Desktop Entry]
                  Version=1.0
                  Type=Application
                  Terminal=false
                  Exec='/home/techy/Documents/myscript.sh'
                  Name=myscript
                  END1
                  chmod +x ~/.config/autostart/myscript.desktop


                  -2- Start the launcher for the first time, it will ask you to validate

                  Browse with file manager to ~/.config/autostart/

                  Double-click on the new created myscript.desktop file

                  Validate the security message popup

                  -3- Done, test it

                  Log-off then log in back in to see it working







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jun 14 '18 at 6:09

























                  answered Jun 14 '18 at 6:02









                  cmak.frcmak.fr

                  2,1341021




                  2,1341021























                      0














                      Not sure about the details of your script in myscript.sh.



                      If your script requires to connect remote host, then you need internet connection in the first place before execution of this script.



                      To solve this, you need to put some delay (Example: sleep 5m) inside your script until internet connection is established successfully.



                      This method solves my problem, but not sure if this works for you too.






                      share|improve this answer








                      New contributor




                      Jerry Chong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.

























                        0














                        Not sure about the details of your script in myscript.sh.



                        If your script requires to connect remote host, then you need internet connection in the first place before execution of this script.



                        To solve this, you need to put some delay (Example: sleep 5m) inside your script until internet connection is established successfully.



                        This method solves my problem, but not sure if this works for you too.






                        share|improve this answer








                        New contributor




                        Jerry Chong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.























                          0












                          0








                          0







                          Not sure about the details of your script in myscript.sh.



                          If your script requires to connect remote host, then you need internet connection in the first place before execution of this script.



                          To solve this, you need to put some delay (Example: sleep 5m) inside your script until internet connection is established successfully.



                          This method solves my problem, but not sure if this works for you too.






                          share|improve this answer








                          New contributor




                          Jerry Chong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.










                          Not sure about the details of your script in myscript.sh.



                          If your script requires to connect remote host, then you need internet connection in the first place before execution of this script.



                          To solve this, you need to put some delay (Example: sleep 5m) inside your script until internet connection is established successfully.



                          This method solves my problem, but not sure if this works for you too.







                          share|improve this answer








                          New contributor




                          Jerry Chong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          share|improve this answer



                          share|improve this answer






                          New contributor




                          Jerry Chong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered 51 mins ago









                          Jerry ChongJerry Chong

                          11




                          11




                          New contributor




                          Jerry Chong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          Jerry Chong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          Jerry Chong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.























                              -1














                              I would try this instead.



                              @reboot sleep 45 && sh /home/techy/Documents/myscript.sh


                              That gives some time to your boot up, and the sh actually calls the shell script.
                              You might need to run chmod -x /home/techy/Documents/myscript.sh this takes restrictions off of the script and path.






                              share|improve this answer
























                              • this does not answer the question

                                – cmak.fr
                                Jun 16 '18 at 23:28
















                              -1














                              I would try this instead.



                              @reboot sleep 45 && sh /home/techy/Documents/myscript.sh


                              That gives some time to your boot up, and the sh actually calls the shell script.
                              You might need to run chmod -x /home/techy/Documents/myscript.sh this takes restrictions off of the script and path.






                              share|improve this answer
























                              • this does not answer the question

                                – cmak.fr
                                Jun 16 '18 at 23:28














                              -1












                              -1








                              -1







                              I would try this instead.



                              @reboot sleep 45 && sh /home/techy/Documents/myscript.sh


                              That gives some time to your boot up, and the sh actually calls the shell script.
                              You might need to run chmod -x /home/techy/Documents/myscript.sh this takes restrictions off of the script and path.






                              share|improve this answer













                              I would try this instead.



                              @reboot sleep 45 && sh /home/techy/Documents/myscript.sh


                              That gives some time to your boot up, and the sh actually calls the shell script.
                              You might need to run chmod -x /home/techy/Documents/myscript.sh this takes restrictions off of the script and path.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Apr 6 '18 at 22:04









                              Sabastion ManneySabastion Manney

                              1




                              1













                              • this does not answer the question

                                – cmak.fr
                                Jun 16 '18 at 23:28



















                              • this does not answer the question

                                – cmak.fr
                                Jun 16 '18 at 23:28

















                              this does not answer the question

                              – cmak.fr
                              Jun 16 '18 at 23:28





                              this does not answer the question

                              – cmak.fr
                              Jun 16 '18 at 23:28











                              -1














                              I've been running into this problem on every boot. Ubuntu wasn't fully loading two hard drivers on my pc. I had to click on them at Nautilus in order to really load the drivers. I noticed that when running Transmission on startup using those drivers as a target for torrent files and it wasn't working.



                              So I had to make this crontab magic and realized that the two commands below are very different indeed:



                              crontab -e

                              sudo crontab -e


                              As I had to use root user's credentials to load the drivers only the second option worked for me and inside crontab file I could write



                              @reboot /folder/loadhd.sh


                              Check this:
                              https://stackoverflow.com/questions/43237488/linux-difference-between-sudo-crontab-e-and-just-crontab-e






                              share|improve this answer


























                              • this does not answer the question

                                – cmak.fr
                                Jun 16 '18 at 23:28
















                              -1














                              I've been running into this problem on every boot. Ubuntu wasn't fully loading two hard drivers on my pc. I had to click on them at Nautilus in order to really load the drivers. I noticed that when running Transmission on startup using those drivers as a target for torrent files and it wasn't working.



                              So I had to make this crontab magic and realized that the two commands below are very different indeed:



                              crontab -e

                              sudo crontab -e


                              As I had to use root user's credentials to load the drivers only the second option worked for me and inside crontab file I could write



                              @reboot /folder/loadhd.sh


                              Check this:
                              https://stackoverflow.com/questions/43237488/linux-difference-between-sudo-crontab-e-and-just-crontab-e






                              share|improve this answer


























                              • this does not answer the question

                                – cmak.fr
                                Jun 16 '18 at 23:28














                              -1












                              -1








                              -1







                              I've been running into this problem on every boot. Ubuntu wasn't fully loading two hard drivers on my pc. I had to click on them at Nautilus in order to really load the drivers. I noticed that when running Transmission on startup using those drivers as a target for torrent files and it wasn't working.



                              So I had to make this crontab magic and realized that the two commands below are very different indeed:



                              crontab -e

                              sudo crontab -e


                              As I had to use root user's credentials to load the drivers only the second option worked for me and inside crontab file I could write



                              @reboot /folder/loadhd.sh


                              Check this:
                              https://stackoverflow.com/questions/43237488/linux-difference-between-sudo-crontab-e-and-just-crontab-e






                              share|improve this answer















                              I've been running into this problem on every boot. Ubuntu wasn't fully loading two hard drivers on my pc. I had to click on them at Nautilus in order to really load the drivers. I noticed that when running Transmission on startup using those drivers as a target for torrent files and it wasn't working.



                              So I had to make this crontab magic and realized that the two commands below are very different indeed:



                              crontab -e

                              sudo crontab -e


                              As I had to use root user's credentials to load the drivers only the second option worked for me and inside crontab file I could write



                              @reboot /folder/loadhd.sh


                              Check this:
                              https://stackoverflow.com/questions/43237488/linux-difference-between-sudo-crontab-e-and-just-crontab-e







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Aug 2 '18 at 16:53

























                              answered Jun 13 '18 at 21:44









                              Valmor NascimentoValmor Nascimento

                              114




                              114













                              • this does not answer the question

                                – cmak.fr
                                Jun 16 '18 at 23:28



















                              • this does not answer the question

                                – cmak.fr
                                Jun 16 '18 at 23:28

















                              this does not answer the question

                              – cmak.fr
                              Jun 16 '18 at 23:28





                              this does not answer the question

                              – cmak.fr
                              Jun 16 '18 at 23:28


















                              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.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f863240%2fcronjob-script-not-running-on-reboot%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

                              GameSpot

                              connect to host localhost port 22: Connection refused

                              Getting a Wifi WPA2 wifi connection