my cron command doesn’t work












2















The commands that runs by source doesn’t work.



crontab -e


*/1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron


Content of cron file is 1.










share|improve this question





























    2















    The commands that runs by source doesn’t work.



    crontab -e


    */1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron


    Content of cron file is 1.










    share|improve this question



























      2












      2








      2








      The commands that runs by source doesn’t work.



      crontab -e


      */1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron


      Content of cron file is 1.










      share|improve this question
















      The commands that runs by source doesn’t work.



      crontab -e


      */1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron


      Content of cron file is 1.







      command-line cron






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 1 hour ago









      dessert

      24.1k670104




      24.1k670104










      asked 3 hours ago









      ahmadahmad

      8510




      8510






















          1 Answer
          1






          active

          oldest

          votes


















          5














          source is a bash-ism (or zsh-ism for that matter) whereas cron uses sh (dash) by default as the shell of choice.



          So you need to use . instead of source to remain POSIX:



          . "$HOME"/.zshrc


          Or you can change the shell to any shell you want by using the SHELL variable of crontab e.g.:



          SHELL=/usr/bin/zsh


          You need to put this near the top of crontab, before any command entry.



          Following your example:



          SHELL=/usr/bin/zsh

          */1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron


          And now you can stick with your original source approach.



          This is the recommended approach for your case as you're source-ing .zshrc, presumably you have zsh specific declarations in there which won't work in sh.



          If you don't want to set the SHELL variable, you can run the whole command as an argument to zsh -c, but this incurs careful quoting.



          A safer approach would be to put the commands in a script, and run that as an executable with #!/usr/bin/env zsh shebang or as an argument to zsh (without making it executable).





          As a side note, always quote your variable expansions unless you intentionally want to have word splitting and pathname expansion on them.






          share|improve this answer


























          • I changed it by but it dosent work yet :*/1 * * * * echo "1" > $HOME/cron && . "$HOME"/.bashrc && echo "2" >> $HOME/cron2

            – ahmad
            3 hours ago













          • @steeldriver Fair call. Edited.

            – heemayl
            3 hours ago











          • @ahmad Check my edits.

            – heemayl
            3 hours ago











          • @steeldriver I Changed it to :*/1 * * * * SHELL=/usr/bin/zsh && echo "1" > $HOME/cron && source "$HOME"/.bashrc && echo "2" >> $HOME/cron2 , But it Dosent work yet :(

            – ahmad
            2 hours ago











          • @ahmad You're supposed to put SHELL=/usr/bin/zsh at the top of your crontab, and keep the command as you've written in the question.

            – heemayl
            2 hours ago











          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%2f1120930%2fmy-cron-command-doesn-t-work%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          5














          source is a bash-ism (or zsh-ism for that matter) whereas cron uses sh (dash) by default as the shell of choice.



          So you need to use . instead of source to remain POSIX:



          . "$HOME"/.zshrc


          Or you can change the shell to any shell you want by using the SHELL variable of crontab e.g.:



          SHELL=/usr/bin/zsh


          You need to put this near the top of crontab, before any command entry.



          Following your example:



          SHELL=/usr/bin/zsh

          */1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron


          And now you can stick with your original source approach.



          This is the recommended approach for your case as you're source-ing .zshrc, presumably you have zsh specific declarations in there which won't work in sh.



          If you don't want to set the SHELL variable, you can run the whole command as an argument to zsh -c, but this incurs careful quoting.



          A safer approach would be to put the commands in a script, and run that as an executable with #!/usr/bin/env zsh shebang or as an argument to zsh (without making it executable).





          As a side note, always quote your variable expansions unless you intentionally want to have word splitting and pathname expansion on them.






          share|improve this answer


























          • I changed it by but it dosent work yet :*/1 * * * * echo "1" > $HOME/cron && . "$HOME"/.bashrc && echo "2" >> $HOME/cron2

            – ahmad
            3 hours ago













          • @steeldriver Fair call. Edited.

            – heemayl
            3 hours ago











          • @ahmad Check my edits.

            – heemayl
            3 hours ago











          • @steeldriver I Changed it to :*/1 * * * * SHELL=/usr/bin/zsh && echo "1" > $HOME/cron && source "$HOME"/.bashrc && echo "2" >> $HOME/cron2 , But it Dosent work yet :(

            – ahmad
            2 hours ago











          • @ahmad You're supposed to put SHELL=/usr/bin/zsh at the top of your crontab, and keep the command as you've written in the question.

            – heemayl
            2 hours ago
















          5














          source is a bash-ism (or zsh-ism for that matter) whereas cron uses sh (dash) by default as the shell of choice.



          So you need to use . instead of source to remain POSIX:



          . "$HOME"/.zshrc


          Or you can change the shell to any shell you want by using the SHELL variable of crontab e.g.:



          SHELL=/usr/bin/zsh


          You need to put this near the top of crontab, before any command entry.



          Following your example:



          SHELL=/usr/bin/zsh

          */1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron


          And now you can stick with your original source approach.



          This is the recommended approach for your case as you're source-ing .zshrc, presumably you have zsh specific declarations in there which won't work in sh.



          If you don't want to set the SHELL variable, you can run the whole command as an argument to zsh -c, but this incurs careful quoting.



          A safer approach would be to put the commands in a script, and run that as an executable with #!/usr/bin/env zsh shebang or as an argument to zsh (without making it executable).





          As a side note, always quote your variable expansions unless you intentionally want to have word splitting and pathname expansion on them.






          share|improve this answer


























          • I changed it by but it dosent work yet :*/1 * * * * echo "1" > $HOME/cron && . "$HOME"/.bashrc && echo "2" >> $HOME/cron2

            – ahmad
            3 hours ago













          • @steeldriver Fair call. Edited.

            – heemayl
            3 hours ago











          • @ahmad Check my edits.

            – heemayl
            3 hours ago











          • @steeldriver I Changed it to :*/1 * * * * SHELL=/usr/bin/zsh && echo "1" > $HOME/cron && source "$HOME"/.bashrc && echo "2" >> $HOME/cron2 , But it Dosent work yet :(

            – ahmad
            2 hours ago











          • @ahmad You're supposed to put SHELL=/usr/bin/zsh at the top of your crontab, and keep the command as you've written in the question.

            – heemayl
            2 hours ago














          5












          5








          5







          source is a bash-ism (or zsh-ism for that matter) whereas cron uses sh (dash) by default as the shell of choice.



          So you need to use . instead of source to remain POSIX:



          . "$HOME"/.zshrc


          Or you can change the shell to any shell you want by using the SHELL variable of crontab e.g.:



          SHELL=/usr/bin/zsh


          You need to put this near the top of crontab, before any command entry.



          Following your example:



          SHELL=/usr/bin/zsh

          */1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron


          And now you can stick with your original source approach.



          This is the recommended approach for your case as you're source-ing .zshrc, presumably you have zsh specific declarations in there which won't work in sh.



          If you don't want to set the SHELL variable, you can run the whole command as an argument to zsh -c, but this incurs careful quoting.



          A safer approach would be to put the commands in a script, and run that as an executable with #!/usr/bin/env zsh shebang or as an argument to zsh (without making it executable).





          As a side note, always quote your variable expansions unless you intentionally want to have word splitting and pathname expansion on them.






          share|improve this answer















          source is a bash-ism (or zsh-ism for that matter) whereas cron uses sh (dash) by default as the shell of choice.



          So you need to use . instead of source to remain POSIX:



          . "$HOME"/.zshrc


          Or you can change the shell to any shell you want by using the SHELL variable of crontab e.g.:



          SHELL=/usr/bin/zsh


          You need to put this near the top of crontab, before any command entry.



          Following your example:



          SHELL=/usr/bin/zsh

          */1 * * * * echo "1" > $HOME/cron && source $HOME/.zshrc && echo "2" >> $HOME/cron2 && source /home/alux/gitHub/rememberMe/.venv/bin/activate && echo "3" >> $HOME/cron && python /home/alux/gitHub/rememberMe/rememberMe/manage.py runcrons > /home/alux/gitHub/rememberMe/rememberMe/cronjobs.log && echo "4" >> $HOME/cron


          And now you can stick with your original source approach.



          This is the recommended approach for your case as you're source-ing .zshrc, presumably you have zsh specific declarations in there which won't work in sh.



          If you don't want to set the SHELL variable, you can run the whole command as an argument to zsh -c, but this incurs careful quoting.



          A safer approach would be to put the commands in a script, and run that as an executable with #!/usr/bin/env zsh shebang or as an argument to zsh (without making it executable).





          As a side note, always quote your variable expansions unless you intentionally want to have word splitting and pathname expansion on them.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 hours ago

























          answered 3 hours ago









          heemaylheemayl

          67.1k9142214




          67.1k9142214













          • I changed it by but it dosent work yet :*/1 * * * * echo "1" > $HOME/cron && . "$HOME"/.bashrc && echo "2" >> $HOME/cron2

            – ahmad
            3 hours ago













          • @steeldriver Fair call. Edited.

            – heemayl
            3 hours ago











          • @ahmad Check my edits.

            – heemayl
            3 hours ago











          • @steeldriver I Changed it to :*/1 * * * * SHELL=/usr/bin/zsh && echo "1" > $HOME/cron && source "$HOME"/.bashrc && echo "2" >> $HOME/cron2 , But it Dosent work yet :(

            – ahmad
            2 hours ago











          • @ahmad You're supposed to put SHELL=/usr/bin/zsh at the top of your crontab, and keep the command as you've written in the question.

            – heemayl
            2 hours ago



















          • I changed it by but it dosent work yet :*/1 * * * * echo "1" > $HOME/cron && . "$HOME"/.bashrc && echo "2" >> $HOME/cron2

            – ahmad
            3 hours ago













          • @steeldriver Fair call. Edited.

            – heemayl
            3 hours ago











          • @ahmad Check my edits.

            – heemayl
            3 hours ago











          • @steeldriver I Changed it to :*/1 * * * * SHELL=/usr/bin/zsh && echo "1" > $HOME/cron && source "$HOME"/.bashrc && echo "2" >> $HOME/cron2 , But it Dosent work yet :(

            – ahmad
            2 hours ago











          • @ahmad You're supposed to put SHELL=/usr/bin/zsh at the top of your crontab, and keep the command as you've written in the question.

            – heemayl
            2 hours ago

















          I changed it by but it dosent work yet :*/1 * * * * echo "1" > $HOME/cron && . "$HOME"/.bashrc && echo "2" >> $HOME/cron2

          – ahmad
          3 hours ago







          I changed it by but it dosent work yet :*/1 * * * * echo "1" > $HOME/cron && . "$HOME"/.bashrc && echo "2" >> $HOME/cron2

          – ahmad
          3 hours ago















          @steeldriver Fair call. Edited.

          – heemayl
          3 hours ago





          @steeldriver Fair call. Edited.

          – heemayl
          3 hours ago













          @ahmad Check my edits.

          – heemayl
          3 hours ago





          @ahmad Check my edits.

          – heemayl
          3 hours ago













          @steeldriver I Changed it to :*/1 * * * * SHELL=/usr/bin/zsh && echo "1" > $HOME/cron && source "$HOME"/.bashrc && echo "2" >> $HOME/cron2 , But it Dosent work yet :(

          – ahmad
          2 hours ago





          @steeldriver I Changed it to :*/1 * * * * SHELL=/usr/bin/zsh && echo "1" > $HOME/cron && source "$HOME"/.bashrc && echo "2" >> $HOME/cron2 , But it Dosent work yet :(

          – ahmad
          2 hours ago













          @ahmad You're supposed to put SHELL=/usr/bin/zsh at the top of your crontab, and keep the command as you've written in the question.

          – heemayl
          2 hours ago





          @ahmad You're supposed to put SHELL=/usr/bin/zsh at the top of your crontab, and keep the command as you've written in the question.

          – heemayl
          2 hours ago


















          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%2f1120930%2fmy-cron-command-doesn-t-work%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

          Callistus I

          Tabula Rosettana

          How to label and detect the document text images