Crontab: Ubuntu running script (noob)Where is the user crontab stored?How do I create a script file for...

What game did these black and yellow dice come from?

Clues on how to solve these types of problems within 2-3 minutes for competitive exams

In Linux what happens if 1000 files in a directory are moved to another location while another 300 files were added to the source directory?

Would tunnel walls be stronger if built using cut granite block walls reinforced with carbon based cords?

A Missing Symbol for This Logo

Non-Cancer terminal illness that can affect young (age 10-13) girls?

TikZ graph edges not drawn nicely

How to make ice magic work from a scientific point of view?

Globe trotting Grandpa. Where is he going next?

How to assess the long-term stability of a college as part of a job search

Is using an 'empty' metaphor considered bad style?

Crontab: Ubuntu running script (noob)

Why didn't Tom Riddle take the presence of Fawkes and the Sorting Hat as more of a threat?

Why did Luke use his left hand to shoot?

How does one write from a minority culture? A question on cultural references

What is the point of publishing a research paper nowadays when even a blog post or a lecture slide can have more citation count than a journal paper?

How do you voice extended chords?

Why does photorec keep finding files after I have filled the disk free space as root?

Building an exterior wall within an exterior wall for insulation

Separate environment for personal and development use under macOS

Boss asked me to sign a resignation paper without a date on it along with my new contract

Can you tell from a blurry photo if focus was too close or too far?

How do I append a character to the end of every line in an excel cell?

Why did Democrats in the Senate oppose the Born-Alive Abortion Survivors Protection Act (2019 S.130)?



Crontab: Ubuntu running script (noob)


Where is the user crontab stored?How do I create a script file for terminal commands?What is the correct way to edit a crontab file?Cannot run bash script from crontab when it works from command line bashBash script not working properly from crontabHelp, ubuntu server 14.04 crontab cannot run my database backup script, but other simple script is okCrontab says command not foundCrontab working but root crontab doesn'tDifficulties running script at startuproot's crontab job not workingRunning pgrep in a crontabPATH issue with Cron - Not running bash/python scriptScript works manually, but not when called by Cron













2















I'm new to crontab and would like to run the following script from /etc/crontab:



0 15    * * *   root    bash-c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'


I have tried with and without bash-c option, yet the script doesn't run.



My objective is:




  1. Get this script running from Crontab

  2. Get this script running on startup


Help is appreciated.










share|improve this question









New contributor




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

























    2















    I'm new to crontab and would like to run the following script from /etc/crontab:



    0 15    * * *   root    bash-c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'


    I have tried with and without bash-c option, yet the script doesn't run.



    My objective is:




    1. Get this script running from Crontab

    2. Get this script running on startup


    Help is appreciated.










    share|improve this question









    New contributor




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























      2












      2








      2








      I'm new to crontab and would like to run the following script from /etc/crontab:



      0 15    * * *   root    bash-c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'


      I have tried with and without bash-c option, yet the script doesn't run.



      My objective is:




      1. Get this script running from Crontab

      2. Get this script running on startup


      Help is appreciated.










      share|improve this question









      New contributor




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












      I'm new to crontab and would like to run the following script from /etc/crontab:



      0 15    * * *   root    bash-c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'


      I have tried with and without bash-c option, yet the script doesn't run.



      My objective is:




      1. Get this script running from Crontab

      2. Get this script running on startup


      Help is appreciated.







      bash scripts cron






      share|improve this question









      New contributor




      orrp 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 question









      New contributor




      orrp 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 question




      share|improve this question








      edited 1 hour ago









      dessert

      24.1k670104




      24.1k670104






      New contributor




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









      asked 1 hour ago









      orrporrp

      112




      112




      New contributor




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





      New contributor





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






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






















          1 Answer
          1






          active

          oldest

          votes


















          5














          You're missing a space after the command bash and the argument -c.



          This should work:



          0 15    * * *  root bash -c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'




          Some additional hints:




          • Don't run a crontab as user root if you don't need to.

          • You wrote that you put it in /etc/crontab file. Don't edit crontab files directly, rather use crontab -e command or sudo crontab -e for commands which need root rights. Note, that you don't put the user field in the "other" crontab files.

          • If you have more than one command you can use bash -c as you do, but I'd rather put the commands in a script and execute this from crontab.


          • To run a script on startup, you can use @reboot instead of 0 15 * * *.







          share|improve this answer





















          • 3





            “I'm not sure what the word root is about here.” See the header of /etc/crontab: Unlike any other crontab you don't have to run the crontab command to install the new version when you edit this file and files in /etc/cron.d. These files also have username fields, that none of the other crontabs do. However, in this case, only the user’s home folder is involved, so root should be not used in this case.

            – Melebius
            58 mins ago













          • thanks, as I never edited /etc/crontab directly I didn't even know this... :-D

            – RoVo
            56 mins ago






          • 1





            See also Two Other Types of Crontab

            – steeldriver
            56 mins ago






          • 1





            I suspect there may be a more fundamental issue with running a bash -c command from cron, since IIRC each command is implicitly executed by /bin/sh -c (or, more exactly, $SHELL -c). It may be necessary to set SHELL=/bin/bash (to suport brace expansion etc.) and then run the command without the bash -c wrapper. But really the best approach (as you note) is to put the bash code in an external script file.

            – steeldriver
            9 mins 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
          });


          }
          });






          orrp is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1121615%2fcrontab-ubuntu-running-script-noob%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














          You're missing a space after the command bash and the argument -c.



          This should work:



          0 15    * * *  root bash -c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'




          Some additional hints:




          • Don't run a crontab as user root if you don't need to.

          • You wrote that you put it in /etc/crontab file. Don't edit crontab files directly, rather use crontab -e command or sudo crontab -e for commands which need root rights. Note, that you don't put the user field in the "other" crontab files.

          • If you have more than one command you can use bash -c as you do, but I'd rather put the commands in a script and execute this from crontab.


          • To run a script on startup, you can use @reboot instead of 0 15 * * *.







          share|improve this answer





















          • 3





            “I'm not sure what the word root is about here.” See the header of /etc/crontab: Unlike any other crontab you don't have to run the crontab command to install the new version when you edit this file and files in /etc/cron.d. These files also have username fields, that none of the other crontabs do. However, in this case, only the user’s home folder is involved, so root should be not used in this case.

            – Melebius
            58 mins ago













          • thanks, as I never edited /etc/crontab directly I didn't even know this... :-D

            – RoVo
            56 mins ago






          • 1





            See also Two Other Types of Crontab

            – steeldriver
            56 mins ago






          • 1





            I suspect there may be a more fundamental issue with running a bash -c command from cron, since IIRC each command is implicitly executed by /bin/sh -c (or, more exactly, $SHELL -c). It may be necessary to set SHELL=/bin/bash (to suport brace expansion etc.) and then run the command without the bash -c wrapper. But really the best approach (as you note) is to put the bash code in an external script file.

            – steeldriver
            9 mins ago
















          5














          You're missing a space after the command bash and the argument -c.



          This should work:



          0 15    * * *  root bash -c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'




          Some additional hints:




          • Don't run a crontab as user root if you don't need to.

          • You wrote that you put it in /etc/crontab file. Don't edit crontab files directly, rather use crontab -e command or sudo crontab -e for commands which need root rights. Note, that you don't put the user field in the "other" crontab files.

          • If you have more than one command you can use bash -c as you do, but I'd rather put the commands in a script and execute this from crontab.


          • To run a script on startup, you can use @reboot instead of 0 15 * * *.







          share|improve this answer





















          • 3





            “I'm not sure what the word root is about here.” See the header of /etc/crontab: Unlike any other crontab you don't have to run the crontab command to install the new version when you edit this file and files in /etc/cron.d. These files also have username fields, that none of the other crontabs do. However, in this case, only the user’s home folder is involved, so root should be not used in this case.

            – Melebius
            58 mins ago













          • thanks, as I never edited /etc/crontab directly I didn't even know this... :-D

            – RoVo
            56 mins ago






          • 1





            See also Two Other Types of Crontab

            – steeldriver
            56 mins ago






          • 1





            I suspect there may be a more fundamental issue with running a bash -c command from cron, since IIRC each command is implicitly executed by /bin/sh -c (or, more exactly, $SHELL -c). It may be necessary to set SHELL=/bin/bash (to suport brace expansion etc.) and then run the command without the bash -c wrapper. But really the best approach (as you note) is to put the bash code in an external script file.

            – steeldriver
            9 mins ago














          5












          5








          5







          You're missing a space after the command bash and the argument -c.



          This should work:



          0 15    * * *  root bash -c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'




          Some additional hints:




          • Don't run a crontab as user root if you don't need to.

          • You wrote that you put it in /etc/crontab file. Don't edit crontab files directly, rather use crontab -e command or sudo crontab -e for commands which need root rights. Note, that you don't put the user field in the "other" crontab files.

          • If you have more than one command you can use bash -c as you do, but I'd rather put the commands in a script and execute this from crontab.


          • To run a script on startup, you can use @reboot instead of 0 15 * * *.







          share|improve this answer















          You're missing a space after the command bash and the argument -c.



          This should work:



          0 15    * * *  root bash -c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'




          Some additional hints:




          • Don't run a crontab as user root if you don't need to.

          • You wrote that you put it in /etc/crontab file. Don't edit crontab files directly, rather use crontab -e command or sudo crontab -e for commands which need root rights. Note, that you don't put the user field in the "other" crontab files.

          • If you have more than one command you can use bash -c as you do, but I'd rather put the commands in a script and execute this from crontab.


          • To run a script on startup, you can use @reboot instead of 0 15 * * *.








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 55 mins ago

























          answered 1 hour ago









          RoVoRoVo

          7,6041842




          7,6041842








          • 3





            “I'm not sure what the word root is about here.” See the header of /etc/crontab: Unlike any other crontab you don't have to run the crontab command to install the new version when you edit this file and files in /etc/cron.d. These files also have username fields, that none of the other crontabs do. However, in this case, only the user’s home folder is involved, so root should be not used in this case.

            – Melebius
            58 mins ago













          • thanks, as I never edited /etc/crontab directly I didn't even know this... :-D

            – RoVo
            56 mins ago






          • 1





            See also Two Other Types of Crontab

            – steeldriver
            56 mins ago






          • 1





            I suspect there may be a more fundamental issue with running a bash -c command from cron, since IIRC each command is implicitly executed by /bin/sh -c (or, more exactly, $SHELL -c). It may be necessary to set SHELL=/bin/bash (to suport brace expansion etc.) and then run the command without the bash -c wrapper. But really the best approach (as you note) is to put the bash code in an external script file.

            – steeldriver
            9 mins ago














          • 3





            “I'm not sure what the word root is about here.” See the header of /etc/crontab: Unlike any other crontab you don't have to run the crontab command to install the new version when you edit this file and files in /etc/cron.d. These files also have username fields, that none of the other crontabs do. However, in this case, only the user’s home folder is involved, so root should be not used in this case.

            – Melebius
            58 mins ago













          • thanks, as I never edited /etc/crontab directly I didn't even know this... :-D

            – RoVo
            56 mins ago






          • 1





            See also Two Other Types of Crontab

            – steeldriver
            56 mins ago






          • 1





            I suspect there may be a more fundamental issue with running a bash -c command from cron, since IIRC each command is implicitly executed by /bin/sh -c (or, more exactly, $SHELL -c). It may be necessary to set SHELL=/bin/bash (to suport brace expansion etc.) and then run the command without the bash -c wrapper. But really the best approach (as you note) is to put the bash code in an external script file.

            – steeldriver
            9 mins ago








          3




          3





          “I'm not sure what the word root is about here.” See the header of /etc/crontab: Unlike any other crontab you don't have to run the crontab command to install the new version when you edit this file and files in /etc/cron.d. These files also have username fields, that none of the other crontabs do. However, in this case, only the user’s home folder is involved, so root should be not used in this case.

          – Melebius
          58 mins ago







          “I'm not sure what the word root is about here.” See the header of /etc/crontab: Unlike any other crontab you don't have to run the crontab command to install the new version when you edit this file and files in /etc/cron.d. These files also have username fields, that none of the other crontabs do. However, in this case, only the user’s home folder is involved, so root should be not used in this case.

          – Melebius
          58 mins ago















          thanks, as I never edited /etc/crontab directly I didn't even know this... :-D

          – RoVo
          56 mins ago





          thanks, as I never edited /etc/crontab directly I didn't even know this... :-D

          – RoVo
          56 mins ago




          1




          1





          See also Two Other Types of Crontab

          – steeldriver
          56 mins ago





          See also Two Other Types of Crontab

          – steeldriver
          56 mins ago




          1




          1





          I suspect there may be a more fundamental issue with running a bash -c command from cron, since IIRC each command is implicitly executed by /bin/sh -c (or, more exactly, $SHELL -c). It may be necessary to set SHELL=/bin/bash (to suport brace expansion etc.) and then run the command without the bash -c wrapper. But really the best approach (as you note) is to put the bash code in an external script file.

          – steeldriver
          9 mins ago





          I suspect there may be a more fundamental issue with running a bash -c command from cron, since IIRC each command is implicitly executed by /bin/sh -c (or, more exactly, $SHELL -c). It may be necessary to set SHELL=/bin/bash (to suport brace expansion etc.) and then run the command without the bash -c wrapper. But really the best approach (as you note) is to put the bash code in an external script file.

          – steeldriver
          9 mins ago










          orrp is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          orrp is a new contributor. Be nice, and check out our Code of Conduct.













          orrp is a new contributor. Be nice, and check out our Code of Conduct.












          orrp is a new contributor. Be nice, and check out our Code of Conduct.
















          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%2f1121615%2fcrontab-ubuntu-running-script-noob%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

          迭戈·戈丁...

          A phrase ”follow into" in a context The 2019 Stack Overflow Developer Survey Results Are...

          1960s short story making fun of James Bond-style spy fiction The 2019 Stack Overflow Developer...