Can't display the date correctly in a file generated by a cronjob [duplicate]











up vote
1
down vote

favorite













This question already has an answer here:




  • How can I execute `date` inside of a cron tab job?

    5 answers




I'm doing a cronjob task which creates a daily database backup. To desctinct the daily files, I name them as follows: dump- (the current date). The backup operation went well, but the date is not interpreted as it should be (dump-$(date '+%Y-%m-%d')) instead of dump-14-12-2018.



#filename=dump-$(date '+%Y-%m-%d')
#*/3 * * * * cd /bdd-backups/ && mysqldump --all-databases >
$filename.sql -u xxx -pxxx









share|improve this question







New contributor




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











marked as duplicate by Jeff Schaller, steeldriver, derobert, Kusalananda, GAD3R yesterday


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    up vote
    1
    down vote

    favorite













    This question already has an answer here:




    • How can I execute `date` inside of a cron tab job?

      5 answers




    I'm doing a cronjob task which creates a daily database backup. To desctinct the daily files, I name them as follows: dump- (the current date). The backup operation went well, but the date is not interpreted as it should be (dump-$(date '+%Y-%m-%d')) instead of dump-14-12-2018.



    #filename=dump-$(date '+%Y-%m-%d')
    #*/3 * * * * cd /bdd-backups/ && mysqldump --all-databases >
    $filename.sql -u xxx -pxxx









    share|improve this question







    New contributor




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











    marked as duplicate by Jeff Schaller, steeldriver, derobert, Kusalananda, GAD3R yesterday


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite












      This question already has an answer here:




      • How can I execute `date` inside of a cron tab job?

        5 answers




      I'm doing a cronjob task which creates a daily database backup. To desctinct the daily files, I name them as follows: dump- (the current date). The backup operation went well, but the date is not interpreted as it should be (dump-$(date '+%Y-%m-%d')) instead of dump-14-12-2018.



      #filename=dump-$(date '+%Y-%m-%d')
      #*/3 * * * * cd /bdd-backups/ && mysqldump --all-databases >
      $filename.sql -u xxx -pxxx









      share|improve this question







      New contributor




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












      This question already has an answer here:




      • How can I execute `date` inside of a cron tab job?

        5 answers




      I'm doing a cronjob task which creates a daily database backup. To desctinct the daily files, I name them as follows: dump- (the current date). The backup operation went well, but the date is not interpreted as it should be (dump-$(date '+%Y-%m-%d')) instead of dump-14-12-2018.



      #filename=dump-$(date '+%Y-%m-%d')
      #*/3 * * * * cd /bdd-backups/ && mysqldump --all-databases >
      $filename.sql -u xxx -pxxx




      This question already has an answer here:




      • How can I execute `date` inside of a cron tab job?

        5 answers








      debian cron






      share|improve this question







      New contributor




      KubiRoazhon 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




      KubiRoazhon 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






      New contributor




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









      asked yesterday









      KubiRoazhon

      1084




      1084




      New contributor




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





      New contributor





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






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




      marked as duplicate by Jeff Schaller, steeldriver, derobert, Kusalananda, GAD3R yesterday


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by Jeff Schaller, steeldriver, derobert, Kusalananda, GAD3R yesterday


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          It's hard to tell what your problem is,
          since you show us a file that's 80% commented out,
          but it looks like you are treating the crontab file
          as if it were a multi-line shell script. 
          It's not; each line is a self-contained, independent entity. 
          So you cannot assign a value to a variable on one line
          and use it on another line.



          Either put everything on one line, or —
          and this is probably better in the long run —
          put the date, cd and mysqldump commands into a separate script file,
          and run the script from crontab.






          share|improve this answer

















          • 1




            Finally, I did a script. Thank you !
            – KubiRoazhon
            yesterday


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          It's hard to tell what your problem is,
          since you show us a file that's 80% commented out,
          but it looks like you are treating the crontab file
          as if it were a multi-line shell script. 
          It's not; each line is a self-contained, independent entity. 
          So you cannot assign a value to a variable on one line
          and use it on another line.



          Either put everything on one line, or —
          and this is probably better in the long run —
          put the date, cd and mysqldump commands into a separate script file,
          and run the script from crontab.






          share|improve this answer

















          • 1




            Finally, I did a script. Thank you !
            – KubiRoazhon
            yesterday















          up vote
          2
          down vote



          accepted










          It's hard to tell what your problem is,
          since you show us a file that's 80% commented out,
          but it looks like you are treating the crontab file
          as if it were a multi-line shell script. 
          It's not; each line is a self-contained, independent entity. 
          So you cannot assign a value to a variable on one line
          and use it on another line.



          Either put everything on one line, or —
          and this is probably better in the long run —
          put the date, cd and mysqldump commands into a separate script file,
          and run the script from crontab.






          share|improve this answer

















          • 1




            Finally, I did a script. Thank you !
            – KubiRoazhon
            yesterday













          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          It's hard to tell what your problem is,
          since you show us a file that's 80% commented out,
          but it looks like you are treating the crontab file
          as if it were a multi-line shell script. 
          It's not; each line is a self-contained, independent entity. 
          So you cannot assign a value to a variable on one line
          and use it on another line.



          Either put everything on one line, or —
          and this is probably better in the long run —
          put the date, cd and mysqldump commands into a separate script file,
          and run the script from crontab.






          share|improve this answer












          It's hard to tell what your problem is,
          since you show us a file that's 80% commented out,
          but it looks like you are treating the crontab file
          as if it were a multi-line shell script. 
          It's not; each line is a self-contained, independent entity. 
          So you cannot assign a value to a variable on one line
          and use it on another line.



          Either put everything on one line, or —
          and this is probably better in the long run —
          put the date, cd and mysqldump commands into a separate script file,
          and run the script from crontab.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          G-Man

          12.9k93264




          12.9k93264








          • 1




            Finally, I did a script. Thank you !
            – KubiRoazhon
            yesterday














          • 1




            Finally, I did a script. Thank you !
            – KubiRoazhon
            yesterday








          1




          1




          Finally, I did a script. Thank you !
          – KubiRoazhon
          yesterday




          Finally, I did a script. Thank you !
          – KubiRoazhon
          yesterday



          Popular posts from this blog

          サソリ

          広島県道265号伴広島線

          Setup Asymptote in Texstudio