Home > Software design >  Crontab unable to run shell script
Crontab unable to run shell script

Time:03-15

I am trying to execute the script using crontab. But when executing manually the script executes, but not with crontab. Tried with root as well as another user, but it doesn't execute the command inside the script.

dbbackup.sh:

d=$(date ' %Y-%m-%d')
kubectl exec -it mariadb-0 -- bash -c "mysqldump -u root -pabc --all-databases > backup/backup-${d}.sql" 

crontab statement:

15 08 * * MON /root/dbbackup.sh

Kindly help with the above issue.

CodePudding user response:

Can you please try with the given command, by adding the SH command in front of the executable file, also I added >> result.log to write the output of the RUN to get errors if any.

Edit: make sure to use sudo in front of the command as this executable file inside the /root folder

15 08 * * MON sudo sh /root/dbbackup.sh >> /home/ubuntu/result.log

To make the script executable, please make sure to run the CHMOD command with the X option

chmod  x root/dbbackup.sh

enter image description here

enter image description here

CodePudding user response:

I was able to resolve the issue, for me, the issue was kubectl binary absolute path was missing( /usr/local/bin/kubectl ).

Thank you for helping.

  • Related