Home > Software engineering >  Crontab does not run bash script
Crontab does not run bash script

Time:01-30

I have created a bash script.

#!/bin/bash
now=$(date  %Y-%m-%d--%H:%M:%S)
mysqldump -uMYUSER -pMYPASSWORD MYDB --no-tablespaces | gzip > ./files/$now.sql.gz

I am trying to run it with a crontab once a day. I typed crontab -e and pasted this:

# m h  dom mon dow   command

0 0 * * * /bin/bash ~/backup/script.sh

I can run the script as-is, but the script never runs by itself.

CodePudding user response:

  1. try to run crontab with root user (sudo crontab -e) ,
  2. locate script in root user folder ~/backup/script.sh

CodePudding user response:

Suggesting to fix your script:

Inject 2nd line with source to current .bash_profile

This will included environment context and path to your cron script.

 sed -i "source $HOME/.bash_profile" <your_script>
  •  Tags:  
  • Related