'Crontab unable to run shell script

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.



Solution 1:[1]

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

Solution 2:[2]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 kdevops