Cronjob output not working [closed]

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











up vote
1
down vote

favorite












I have this cronjob:



#!/bin/bash
YEAR=`date +%Y`
MONTH=`date +%m`
DAY=`date +%d`
mkdir -p $YEAR/$MONTH/$DAY
mysqldump -uroot -p1234 locatari > $YEAR/$MONTH/$DAY/backup.sql


And I want to run this at each let's say 3 minutes. I tried with each of these crontab commands and none on them seems to work:



3 * * * * /usr/bin /home/rome/cronjob/back.sh > /home/rome/cronjob
3 * * * * /home/rome/cronjob/back.sh/
3 * * * * exec `/bin/bash /home/rome/cronjob/back.sh`
3 * * * * /bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1


I only made it run when I did:



bash back.sh


All worked as expected with the bash command, what is wrong to my cron scheduler? Problem is that with the crontab command, I can't see my output, it only works with bash command.







share|improve this question













closed as off-topic by roaima, andcoz, slm♦ Jun 22 at 0:35


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – roaima, andcoz, slm
If this question can be reworded to fit the rules in the help center, please edit the question.
















    up vote
    1
    down vote

    favorite












    I have this cronjob:



    #!/bin/bash
    YEAR=`date +%Y`
    MONTH=`date +%m`
    DAY=`date +%d`
    mkdir -p $YEAR/$MONTH/$DAY
    mysqldump -uroot -p1234 locatari > $YEAR/$MONTH/$DAY/backup.sql


    And I want to run this at each let's say 3 minutes. I tried with each of these crontab commands and none on them seems to work:



    3 * * * * /usr/bin /home/rome/cronjob/back.sh > /home/rome/cronjob
    3 * * * * /home/rome/cronjob/back.sh/
    3 * * * * exec `/bin/bash /home/rome/cronjob/back.sh`
    3 * * * * /bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1


    I only made it run when I did:



    bash back.sh


    All worked as expected with the bash command, what is wrong to my cron scheduler? Problem is that with the crontab command, I can't see my output, it only works with bash command.







    share|improve this question













    closed as off-topic by roaima, andcoz, slm♦ Jun 22 at 0:35


    This question appears to be off-topic. The users who voted to close gave this specific reason:


    • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – roaima, andcoz, slm
    If this question can be reworded to fit the rules in the help center, please edit the question.














      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have this cronjob:



      #!/bin/bash
      YEAR=`date +%Y`
      MONTH=`date +%m`
      DAY=`date +%d`
      mkdir -p $YEAR/$MONTH/$DAY
      mysqldump -uroot -p1234 locatari > $YEAR/$MONTH/$DAY/backup.sql


      And I want to run this at each let's say 3 minutes. I tried with each of these crontab commands and none on them seems to work:



      3 * * * * /usr/bin /home/rome/cronjob/back.sh > /home/rome/cronjob
      3 * * * * /home/rome/cronjob/back.sh/
      3 * * * * exec `/bin/bash /home/rome/cronjob/back.sh`
      3 * * * * /bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1


      I only made it run when I did:



      bash back.sh


      All worked as expected with the bash command, what is wrong to my cron scheduler? Problem is that with the crontab command, I can't see my output, it only works with bash command.







      share|improve this question













      I have this cronjob:



      #!/bin/bash
      YEAR=`date +%Y`
      MONTH=`date +%m`
      DAY=`date +%d`
      mkdir -p $YEAR/$MONTH/$DAY
      mysqldump -uroot -p1234 locatari > $YEAR/$MONTH/$DAY/backup.sql


      And I want to run this at each let's say 3 minutes. I tried with each of these crontab commands and none on them seems to work:



      3 * * * * /usr/bin /home/rome/cronjob/back.sh > /home/rome/cronjob
      3 * * * * /home/rome/cronjob/back.sh/
      3 * * * * exec `/bin/bash /home/rome/cronjob/back.sh`
      3 * * * * /bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1


      I only made it run when I did:



      bash back.sh


      All worked as expected with the bash command, what is wrong to my cron scheduler? Problem is that with the crontab command, I can't see my output, it only works with bash command.









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jun 21 at 13:08
























      asked Jun 21 at 12:43









      Tatu Bogdan

      84




      84




      closed as off-topic by roaima, andcoz, slm♦ Jun 22 at 0:35


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – roaima, andcoz, slm
      If this question can be reworded to fit the rules in the help center, please edit the question.




      closed as off-topic by roaima, andcoz, slm♦ Jun 22 at 0:35


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – roaima, andcoz, slm
      If this question can be reworded to fit the rules in the help center, please edit the question.




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          None of your crontab job entries matches what you typed at the command line




          1. /usr/bin /home/rome/cronjob/back.sh tries to run a program /usr/bin, but that's a directory


          2. /home/rome/cronjob/back.sh/ tries to treat your script as a directory


          3. exec `/bin/bash /home/rome/cronjob/back.sh` tries to use the output of your program as a program name to run


          4. /bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1 this might work, except that you have thrown away all the output of the script, so you won't see any errors

          Based on feedback from your comments it seems you probably want something like this (I've omitted /home/rome because that is your home directory anyway):



          */3 * * * * cd cronjob && bash back.sh >back.log 2>&1





          share|improve this answer























          • Sorry for the typo in my post, it was: bash back.sh, my bash file is back.sh, but I was using the name properly in my tests, anyway I was testing your last exemple, I got only the file backuplog with the text: mysqldump: [Warning] Using a password on the command line interface can be insecure, the same text runs when I bash back.sh, but the problem is that it won't generate the file, bash back.sh generates.
            – Tatu Bogdan
            Jun 21 at 13:05










          • @TatuBogdan what directory do you run the bash back.sh command from, when you do it yourself? (Your home directory? Somewhere else?)
            – roaima
            Jun 21 at 13:10










          • cd /home/rome/cronjob and then bash back.sh
            – Tatu Bogdan
            Jun 21 at 13:12











          • @TatuBogdan is /home/rome your home directory? Also, have you looked in ~/2018/06/21 for your dump file from crontab?
            – roaima
            Jun 21 at 13:15











          • Yes, and that is the full route to my sh file: /home/rome/cronjob, I can't find any created directory.
            – Tatu Bogdan
            Jun 21 at 13:25

















          up vote
          2
          down vote













          Your cron schedule expression means "At every minute 3" => each hour.

          Every 3 minutes would be:



          */3 * * * *


          See this nice tool to check the expression.



          Also only your last cron command will work. But I would not redirect the output to /dev/null. If there are any problems with your script, it's difficult to debug.






          share|improve this answer






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted










            None of your crontab job entries matches what you typed at the command line




            1. /usr/bin /home/rome/cronjob/back.sh tries to run a program /usr/bin, but that's a directory


            2. /home/rome/cronjob/back.sh/ tries to treat your script as a directory


            3. exec `/bin/bash /home/rome/cronjob/back.sh` tries to use the output of your program as a program name to run


            4. /bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1 this might work, except that you have thrown away all the output of the script, so you won't see any errors

            Based on feedback from your comments it seems you probably want something like this (I've omitted /home/rome because that is your home directory anyway):



            */3 * * * * cd cronjob && bash back.sh >back.log 2>&1





            share|improve this answer























            • Sorry for the typo in my post, it was: bash back.sh, my bash file is back.sh, but I was using the name properly in my tests, anyway I was testing your last exemple, I got only the file backuplog with the text: mysqldump: [Warning] Using a password on the command line interface can be insecure, the same text runs when I bash back.sh, but the problem is that it won't generate the file, bash back.sh generates.
              – Tatu Bogdan
              Jun 21 at 13:05










            • @TatuBogdan what directory do you run the bash back.sh command from, when you do it yourself? (Your home directory? Somewhere else?)
              – roaima
              Jun 21 at 13:10










            • cd /home/rome/cronjob and then bash back.sh
              – Tatu Bogdan
              Jun 21 at 13:12











            • @TatuBogdan is /home/rome your home directory? Also, have you looked in ~/2018/06/21 for your dump file from crontab?
              – roaima
              Jun 21 at 13:15











            • Yes, and that is the full route to my sh file: /home/rome/cronjob, I can't find any created directory.
              – Tatu Bogdan
              Jun 21 at 13:25














            up vote
            2
            down vote



            accepted










            None of your crontab job entries matches what you typed at the command line




            1. /usr/bin /home/rome/cronjob/back.sh tries to run a program /usr/bin, but that's a directory


            2. /home/rome/cronjob/back.sh/ tries to treat your script as a directory


            3. exec `/bin/bash /home/rome/cronjob/back.sh` tries to use the output of your program as a program name to run


            4. /bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1 this might work, except that you have thrown away all the output of the script, so you won't see any errors

            Based on feedback from your comments it seems you probably want something like this (I've omitted /home/rome because that is your home directory anyway):



            */3 * * * * cd cronjob && bash back.sh >back.log 2>&1





            share|improve this answer























            • Sorry for the typo in my post, it was: bash back.sh, my bash file is back.sh, but I was using the name properly in my tests, anyway I was testing your last exemple, I got only the file backuplog with the text: mysqldump: [Warning] Using a password on the command line interface can be insecure, the same text runs when I bash back.sh, but the problem is that it won't generate the file, bash back.sh generates.
              – Tatu Bogdan
              Jun 21 at 13:05










            • @TatuBogdan what directory do you run the bash back.sh command from, when you do it yourself? (Your home directory? Somewhere else?)
              – roaima
              Jun 21 at 13:10










            • cd /home/rome/cronjob and then bash back.sh
              – Tatu Bogdan
              Jun 21 at 13:12











            • @TatuBogdan is /home/rome your home directory? Also, have you looked in ~/2018/06/21 for your dump file from crontab?
              – roaima
              Jun 21 at 13:15











            • Yes, and that is the full route to my sh file: /home/rome/cronjob, I can't find any created directory.
              – Tatu Bogdan
              Jun 21 at 13:25












            up vote
            2
            down vote



            accepted







            up vote
            2
            down vote



            accepted






            None of your crontab job entries matches what you typed at the command line




            1. /usr/bin /home/rome/cronjob/back.sh tries to run a program /usr/bin, but that's a directory


            2. /home/rome/cronjob/back.sh/ tries to treat your script as a directory


            3. exec `/bin/bash /home/rome/cronjob/back.sh` tries to use the output of your program as a program name to run


            4. /bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1 this might work, except that you have thrown away all the output of the script, so you won't see any errors

            Based on feedback from your comments it seems you probably want something like this (I've omitted /home/rome because that is your home directory anyway):



            */3 * * * * cd cronjob && bash back.sh >back.log 2>&1





            share|improve this answer















            None of your crontab job entries matches what you typed at the command line




            1. /usr/bin /home/rome/cronjob/back.sh tries to run a program /usr/bin, but that's a directory


            2. /home/rome/cronjob/back.sh/ tries to treat your script as a directory


            3. exec `/bin/bash /home/rome/cronjob/back.sh` tries to use the output of your program as a program name to run


            4. /bin/bash /home/rome/cronjob/back.sh > /dev/null 2>&1 this might work, except that you have thrown away all the output of the script, so you won't see any errors

            Based on feedback from your comments it seems you probably want something like this (I've omitted /home/rome because that is your home directory anyway):



            */3 * * * * cd cronjob && bash back.sh >back.log 2>&1






            share|improve this answer















            share|improve this answer



            share|improve this answer








            edited Jun 21 at 13:56


























            answered Jun 21 at 12:51









            roaima

            39.2k544105




            39.2k544105











            • Sorry for the typo in my post, it was: bash back.sh, my bash file is back.sh, but I was using the name properly in my tests, anyway I was testing your last exemple, I got only the file backuplog with the text: mysqldump: [Warning] Using a password on the command line interface can be insecure, the same text runs when I bash back.sh, but the problem is that it won't generate the file, bash back.sh generates.
              – Tatu Bogdan
              Jun 21 at 13:05










            • @TatuBogdan what directory do you run the bash back.sh command from, when you do it yourself? (Your home directory? Somewhere else?)
              – roaima
              Jun 21 at 13:10










            • cd /home/rome/cronjob and then bash back.sh
              – Tatu Bogdan
              Jun 21 at 13:12











            • @TatuBogdan is /home/rome your home directory? Also, have you looked in ~/2018/06/21 for your dump file from crontab?
              – roaima
              Jun 21 at 13:15











            • Yes, and that is the full route to my sh file: /home/rome/cronjob, I can't find any created directory.
              – Tatu Bogdan
              Jun 21 at 13:25
















            • Sorry for the typo in my post, it was: bash back.sh, my bash file is back.sh, but I was using the name properly in my tests, anyway I was testing your last exemple, I got only the file backuplog with the text: mysqldump: [Warning] Using a password on the command line interface can be insecure, the same text runs when I bash back.sh, but the problem is that it won't generate the file, bash back.sh generates.
              – Tatu Bogdan
              Jun 21 at 13:05










            • @TatuBogdan what directory do you run the bash back.sh command from, when you do it yourself? (Your home directory? Somewhere else?)
              – roaima
              Jun 21 at 13:10










            • cd /home/rome/cronjob and then bash back.sh
              – Tatu Bogdan
              Jun 21 at 13:12











            • @TatuBogdan is /home/rome your home directory? Also, have you looked in ~/2018/06/21 for your dump file from crontab?
              – roaima
              Jun 21 at 13:15











            • Yes, and that is the full route to my sh file: /home/rome/cronjob, I can't find any created directory.
              – Tatu Bogdan
              Jun 21 at 13:25















            Sorry for the typo in my post, it was: bash back.sh, my bash file is back.sh, but I was using the name properly in my tests, anyway I was testing your last exemple, I got only the file backuplog with the text: mysqldump: [Warning] Using a password on the command line interface can be insecure, the same text runs when I bash back.sh, but the problem is that it won't generate the file, bash back.sh generates.
            – Tatu Bogdan
            Jun 21 at 13:05




            Sorry for the typo in my post, it was: bash back.sh, my bash file is back.sh, but I was using the name properly in my tests, anyway I was testing your last exemple, I got only the file backuplog with the text: mysqldump: [Warning] Using a password on the command line interface can be insecure, the same text runs when I bash back.sh, but the problem is that it won't generate the file, bash back.sh generates.
            – Tatu Bogdan
            Jun 21 at 13:05












            @TatuBogdan what directory do you run the bash back.sh command from, when you do it yourself? (Your home directory? Somewhere else?)
            – roaima
            Jun 21 at 13:10




            @TatuBogdan what directory do you run the bash back.sh command from, when you do it yourself? (Your home directory? Somewhere else?)
            – roaima
            Jun 21 at 13:10












            cd /home/rome/cronjob and then bash back.sh
            – Tatu Bogdan
            Jun 21 at 13:12





            cd /home/rome/cronjob and then bash back.sh
            – Tatu Bogdan
            Jun 21 at 13:12













            @TatuBogdan is /home/rome your home directory? Also, have you looked in ~/2018/06/21 for your dump file from crontab?
            – roaima
            Jun 21 at 13:15





            @TatuBogdan is /home/rome your home directory? Also, have you looked in ~/2018/06/21 for your dump file from crontab?
            – roaima
            Jun 21 at 13:15













            Yes, and that is the full route to my sh file: /home/rome/cronjob, I can't find any created directory.
            – Tatu Bogdan
            Jun 21 at 13:25




            Yes, and that is the full route to my sh file: /home/rome/cronjob, I can't find any created directory.
            – Tatu Bogdan
            Jun 21 at 13:25












            up vote
            2
            down vote













            Your cron schedule expression means "At every minute 3" => each hour.

            Every 3 minutes would be:



            */3 * * * *


            See this nice tool to check the expression.



            Also only your last cron command will work. But I would not redirect the output to /dev/null. If there are any problems with your script, it's difficult to debug.






            share|improve this answer



























              up vote
              2
              down vote













              Your cron schedule expression means "At every minute 3" => each hour.

              Every 3 minutes would be:



              */3 * * * *


              See this nice tool to check the expression.



              Also only your last cron command will work. But I would not redirect the output to /dev/null. If there are any problems with your script, it's difficult to debug.






              share|improve this answer

























                up vote
                2
                down vote










                up vote
                2
                down vote









                Your cron schedule expression means "At every minute 3" => each hour.

                Every 3 minutes would be:



                */3 * * * *


                See this nice tool to check the expression.



                Also only your last cron command will work. But I would not redirect the output to /dev/null. If there are any problems with your script, it's difficult to debug.






                share|improve this answer















                Your cron schedule expression means "At every minute 3" => each hour.

                Every 3 minutes would be:



                */3 * * * *


                See this nice tool to check the expression.



                Also only your last cron command will work. But I would not redirect the output to /dev/null. If there are any problems with your script, it's difficult to debug.







                share|improve this answer















                share|improve this answer



                share|improve this answer








                edited Jun 21 at 13:03


























                answered Jun 21 at 12:51









                RoVo

                83219




                83219












                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay