I have a cron job supposed to trigger a shell script daily at 2 AM.
0 2 * * * /root/bin/script.sh
However it does not work at all. What am I missing?
More details: The script runs fine without cron scheduling when run manually and does what it is supposed to do. Root user is running the cron job. The cron job was scheduled by crontab -e
as root
user. pgrep cron
gives a service id which means that cron service is running. Following are the contents of /root/bin/script.sh
file:
BACKUP_LOG=/var/log/backup.log
exec 1> >(while IFS= read -r line; do echo "$(date --rfc-3339 ns) $line"; done | tee -a ${BACKUP_LOG}) 2>&1
# Back up the etc directory
mkdir /home/directory1/backup/etc_backup
cp -Lrp /etc /home/data/backup/etc_backup
tar czf /home/data/backup/etc_backup.tgz
/home/data/backup/etc_backup
rm -rf /home/data/backup/etc_backup
Actually I moved the script from /etc/cron.daily/
to /root/bin
. Is the script supposed to be in /etc/cron.daily
only for daily execution?
crontab -e
(as what user?) or did you edit/etc/cron/crontab
? Does the script work if run manually? What does the script do? Does it call other programs? We need to see the script to know if it would work with cron. Is your cron service running? Give us something to go on, we don't have access to your machine!