Issues getting crontab to work.

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
0
down vote

favorite












Hey guys I'm really new to linux and still learning so hopefully this will be an easy one for you guys.



I'm trying to learn more about how to use cron to schedule events on my ubuntu machine. Right now I have a script (script.sh) that is as follows:



#!/bin/bash

echo "I work"


I log into terminal as root (sudo -i) and am entering:



sudo bash /home/lskidson/tests/script.sh 


It properly executes the script when I do this. (Still logged on as root) I have a crontab set up to execute this script every minute that I can not get to work it is as follows (I set it up using crontab -e)



* * * * * sudo bash /home/lskidson/tests/script.sh


I write it to the file then when I print the job list (crontab -l) it appears properly as I have asked it to. However, the script never runs.



Do you guys have any general tips as to what could be wrong? I can provide more info if needed. Thanks in advance!










share|improve this question

























    up vote
    0
    down vote

    favorite












    Hey guys I'm really new to linux and still learning so hopefully this will be an easy one for you guys.



    I'm trying to learn more about how to use cron to schedule events on my ubuntu machine. Right now I have a script (script.sh) that is as follows:



    #!/bin/bash

    echo "I work"


    I log into terminal as root (sudo -i) and am entering:



    sudo bash /home/lskidson/tests/script.sh 


    It properly executes the script when I do this. (Still logged on as root) I have a crontab set up to execute this script every minute that I can not get to work it is as follows (I set it up using crontab -e)



    * * * * * sudo bash /home/lskidson/tests/script.sh


    I write it to the file then when I print the job list (crontab -l) it appears properly as I have asked it to. However, the script never runs.



    Do you guys have any general tips as to what could be wrong? I can provide more info if needed. Thanks in advance!










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Hey guys I'm really new to linux and still learning so hopefully this will be an easy one for you guys.



      I'm trying to learn more about how to use cron to schedule events on my ubuntu machine. Right now I have a script (script.sh) that is as follows:



      #!/bin/bash

      echo "I work"


      I log into terminal as root (sudo -i) and am entering:



      sudo bash /home/lskidson/tests/script.sh 


      It properly executes the script when I do this. (Still logged on as root) I have a crontab set up to execute this script every minute that I can not get to work it is as follows (I set it up using crontab -e)



      * * * * * sudo bash /home/lskidson/tests/script.sh


      I write it to the file then when I print the job list (crontab -l) it appears properly as I have asked it to. However, the script never runs.



      Do you guys have any general tips as to what could be wrong? I can provide more info if needed. Thanks in advance!










      share|improve this question













      Hey guys I'm really new to linux and still learning so hopefully this will be an easy one for you guys.



      I'm trying to learn more about how to use cron to schedule events on my ubuntu machine. Right now I have a script (script.sh) that is as follows:



      #!/bin/bash

      echo "I work"


      I log into terminal as root (sudo -i) and am entering:



      sudo bash /home/lskidson/tests/script.sh 


      It properly executes the script when I do this. (Still logged on as root) I have a crontab set up to execute this script every minute that I can not get to work it is as follows (I set it up using crontab -e)



      * * * * * sudo bash /home/lskidson/tests/script.sh


      I write it to the file then when I print the job list (crontab -l) it appears properly as I have asked it to. However, the script never runs.



      Do you guys have any general tips as to what could be wrong? I can provide more info if needed. Thanks in advance!







      scripts cron






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 22 at 16:10









      LSKidson

      33




      33




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          How do you know it never runs? It is not going to echo to your terminal. First drop the sudo...that should never be in a cronjob. A crontab for root runs as root, the crontab for a user runs as the user, place your script accordingly.



          Pipe your output to file like so



          echo "I work" > /path/to/some/file.txt


          or



          * * * * * /home/lskidson/tests/script.sh > /path/to/some/file.txt


          Use > to overwrite the file, >> to append to it.






          share|improve this answer



























            up vote
            1
            down vote













            Firs with the shebang #!/bin/bash you already defined this is a Bash script. Next step is to create the file executable to run it without the command bash in from of it:



            chmod +x /home/lskidson/tests/script.sh 


            In general the command sudo is not applicable within crontab. If you need to run Cronjob by root you can use the root's crontab, that can be achieved by the command sudo crontab -e.



            Now we can go to the Crontab's question. Where you expect to receive the message "I work"? There are few cases.



            1. If the executable file generates an output file, or just modifies some things, the Cron job should be:



            * * * * * /home/lskidson/tests/script.sh 


            2. If the program doesn't write any output file and just generates some data within the stdout (as it is in your case), you should redirect it to a file to see it into an appropriate place (this part 2>&1 redirects and the error messages to stdout):



            * * * * * /home/lskidson/tests/script.sh >> /home/lskidson/tests/script.sh.log 2>&1


            3. While the stdout isn't redirected, Cron will sending local mails to the user (if your local mail is setup properly), unless this is overridden by setting the variable MAILTO in crontab:



            MAILTO="my@custom.mail"
            * * * * * /home/lskidson/tests/script.sh


            References:



            • How to detect error in cron jobs


            • How do I make cron create cron.log?





            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',
              convertImagesToLinks: true,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              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%2f1018296%2fissues-getting-crontab-to-work%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote



              accepted










              How do you know it never runs? It is not going to echo to your terminal. First drop the sudo...that should never be in a cronjob. A crontab for root runs as root, the crontab for a user runs as the user, place your script accordingly.



              Pipe your output to file like so



              echo "I work" > /path/to/some/file.txt


              or



              * * * * * /home/lskidson/tests/script.sh > /path/to/some/file.txt


              Use > to overwrite the file, >> to append to it.






              share|improve this answer
























                up vote
                1
                down vote



                accepted










                How do you know it never runs? It is not going to echo to your terminal. First drop the sudo...that should never be in a cronjob. A crontab for root runs as root, the crontab for a user runs as the user, place your script accordingly.



                Pipe your output to file like so



                echo "I work" > /path/to/some/file.txt


                or



                * * * * * /home/lskidson/tests/script.sh > /path/to/some/file.txt


                Use > to overwrite the file, >> to append to it.






                share|improve this answer






















                  up vote
                  1
                  down vote



                  accepted







                  up vote
                  1
                  down vote



                  accepted






                  How do you know it never runs? It is not going to echo to your terminal. First drop the sudo...that should never be in a cronjob. A crontab for root runs as root, the crontab for a user runs as the user, place your script accordingly.



                  Pipe your output to file like so



                  echo "I work" > /path/to/some/file.txt


                  or



                  * * * * * /home/lskidson/tests/script.sh > /path/to/some/file.txt


                  Use > to overwrite the file, >> to append to it.






                  share|improve this answer












                  How do you know it never runs? It is not going to echo to your terminal. First drop the sudo...that should never be in a cronjob. A crontab for root runs as root, the crontab for a user runs as the user, place your script accordingly.



                  Pipe your output to file like so



                  echo "I work" > /path/to/some/file.txt


                  or



                  * * * * * /home/lskidson/tests/script.sh > /path/to/some/file.txt


                  Use > to overwrite the file, >> to append to it.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 22 at 16:38









                  rtaft

                  397111




                  397111






















                      up vote
                      1
                      down vote













                      Firs with the shebang #!/bin/bash you already defined this is a Bash script. Next step is to create the file executable to run it without the command bash in from of it:



                      chmod +x /home/lskidson/tests/script.sh 


                      In general the command sudo is not applicable within crontab. If you need to run Cronjob by root you can use the root's crontab, that can be achieved by the command sudo crontab -e.



                      Now we can go to the Crontab's question. Where you expect to receive the message "I work"? There are few cases.



                      1. If the executable file generates an output file, or just modifies some things, the Cron job should be:



                      * * * * * /home/lskidson/tests/script.sh 


                      2. If the program doesn't write any output file and just generates some data within the stdout (as it is in your case), you should redirect it to a file to see it into an appropriate place (this part 2>&1 redirects and the error messages to stdout):



                      * * * * * /home/lskidson/tests/script.sh >> /home/lskidson/tests/script.sh.log 2>&1


                      3. While the stdout isn't redirected, Cron will sending local mails to the user (if your local mail is setup properly), unless this is overridden by setting the variable MAILTO in crontab:



                      MAILTO="my@custom.mail"
                      * * * * * /home/lskidson/tests/script.sh


                      References:



                      • How to detect error in cron jobs


                      • How do I make cron create cron.log?





                      share|improve this answer
























                        up vote
                        1
                        down vote













                        Firs with the shebang #!/bin/bash you already defined this is a Bash script. Next step is to create the file executable to run it without the command bash in from of it:



                        chmod +x /home/lskidson/tests/script.sh 


                        In general the command sudo is not applicable within crontab. If you need to run Cronjob by root you can use the root's crontab, that can be achieved by the command sudo crontab -e.



                        Now we can go to the Crontab's question. Where you expect to receive the message "I work"? There are few cases.



                        1. If the executable file generates an output file, or just modifies some things, the Cron job should be:



                        * * * * * /home/lskidson/tests/script.sh 


                        2. If the program doesn't write any output file and just generates some data within the stdout (as it is in your case), you should redirect it to a file to see it into an appropriate place (this part 2>&1 redirects and the error messages to stdout):



                        * * * * * /home/lskidson/tests/script.sh >> /home/lskidson/tests/script.sh.log 2>&1


                        3. While the stdout isn't redirected, Cron will sending local mails to the user (if your local mail is setup properly), unless this is overridden by setting the variable MAILTO in crontab:



                        MAILTO="my@custom.mail"
                        * * * * * /home/lskidson/tests/script.sh


                        References:



                        • How to detect error in cron jobs


                        • How do I make cron create cron.log?





                        share|improve this answer






















                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          Firs with the shebang #!/bin/bash you already defined this is a Bash script. Next step is to create the file executable to run it without the command bash in from of it:



                          chmod +x /home/lskidson/tests/script.sh 


                          In general the command sudo is not applicable within crontab. If you need to run Cronjob by root you can use the root's crontab, that can be achieved by the command sudo crontab -e.



                          Now we can go to the Crontab's question. Where you expect to receive the message "I work"? There are few cases.



                          1. If the executable file generates an output file, or just modifies some things, the Cron job should be:



                          * * * * * /home/lskidson/tests/script.sh 


                          2. If the program doesn't write any output file and just generates some data within the stdout (as it is in your case), you should redirect it to a file to see it into an appropriate place (this part 2>&1 redirects and the error messages to stdout):



                          * * * * * /home/lskidson/tests/script.sh >> /home/lskidson/tests/script.sh.log 2>&1


                          3. While the stdout isn't redirected, Cron will sending local mails to the user (if your local mail is setup properly), unless this is overridden by setting the variable MAILTO in crontab:



                          MAILTO="my@custom.mail"
                          * * * * * /home/lskidson/tests/script.sh


                          References:



                          • How to detect error in cron jobs


                          • How do I make cron create cron.log?





                          share|improve this answer












                          Firs with the shebang #!/bin/bash you already defined this is a Bash script. Next step is to create the file executable to run it without the command bash in from of it:



                          chmod +x /home/lskidson/tests/script.sh 


                          In general the command sudo is not applicable within crontab. If you need to run Cronjob by root you can use the root's crontab, that can be achieved by the command sudo crontab -e.



                          Now we can go to the Crontab's question. Where you expect to receive the message "I work"? There are few cases.



                          1. If the executable file generates an output file, or just modifies some things, the Cron job should be:



                          * * * * * /home/lskidson/tests/script.sh 


                          2. If the program doesn't write any output file and just generates some data within the stdout (as it is in your case), you should redirect it to a file to see it into an appropriate place (this part 2>&1 redirects and the error messages to stdout):



                          * * * * * /home/lskidson/tests/script.sh >> /home/lskidson/tests/script.sh.log 2>&1


                          3. While the stdout isn't redirected, Cron will sending local mails to the user (if your local mail is setup properly), unless this is overridden by setting the variable MAILTO in crontab:



                          MAILTO="my@custom.mail"
                          * * * * * /home/lskidson/tests/script.sh


                          References:



                          • How to detect error in cron jobs


                          • How do I make cron create cron.log?






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 22 at 16:46









                          pa4080

                          12.3k52256




                          12.3k52256



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1018296%2fissues-getting-crontab-to-work%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              pylint3 and pip3 broken

                              Missing snmpget and snmpwalk

                              How to enroll fingerprints to Ubuntu 17.10 with VFS491