In my scheduled task tab i have
# run backup midnight and noon
0 0,12 * * * /mnt/usb1/shareroot/software/openwrt/flint2/scripts/backup_with_email.sh
the backup job itself is a combination of a few scripts
backup_with_email.sh:
#!/bin/sh
LOG_FILE="/mnt/usb1/shareroot/software/openwrt/flint2/scripts/backuplog.log"
START=$(date +%s)
# Use full path to ensure it runs regardless of where you call the script from
/mnt/usb1/shareroot/software/openwrt/flint2/scripts/backup_with_log.sh
END=$(date +%s)
# 1. Added "$" to variable: $(cat "$LOG_FILE")
# 2. Used printf for reliable newlines (\n) in sh
# 3. Quoted variables to handle potential spaces
printf "Subject: Skittles backup finished in $((END-START)) seconds\n\nLOG:\n$(cat "$LOG_FILE")" | sendmail -t og@hotmail.com
backup_with_log.sh:
LOG_FILE="/mnt/usb1/shareroot/software/openwrt/flint2/scripts/backuplog.log"
{
./backup.sh
}> ${LOG_FILE}
backup.sh:
echo "starting backup "$(date)
echo "/mnt/usb1/shareroot/ TO /mnt/usb2/shareroot "$(date)
rsync -avhzz --delete /mnt/usb1/shareroot/ /mnt/usb2/shareroot/
echo "/etc/ TO /mnt/usb2/openwrt_backup/etc "$(date)
rsync -avhzz --delete /etc/ /mnt/usb2/openwrt_backup/etc/
echo "/var/ TO /mnt/usb2/openwrt_backup/etc "$(date)
rsync -avhzz --delete /var/ /mnt/usb2/openwrt_backup/var/
echo "/mnt/usb1/minidlna/ TO /mnt/usb2/minidlna "$(date)
rsync -avhzz --delete /mnt/usb1/minidlna/ /mnt/usb2/minidlna/
echo "/mnt/usb1/torrent/ TO /mnt/usb2/torrent/ "$(date)
rsync -avhzz --delete /mnt/usb1/torrent/ /mnt/usb2/torrent/
echo "/mnt/usb1/gitrepos/ TO /mnt/usb2/gitrepos/ "$(date)
rsync -avhzz --delete /mnt/usb1/gitrepos/ /mnt/usb2/gitrepos/
echo "finished backup "$(date)
when i run this within an ssh session, or even in the Custom Commands tab it runs properly. I see the log message of what new changes where synced and the email sends the log in the body!!!
however as a Scheduled Job the log is completely empty as well as the body of the email and things are NOT synced.
permissions:
root@skittles:/mnt/usb1/shareroot/software/openwrt/flint2/scripts# ll
drwxrwxrwx 4 root root 4096 Jul 9 2025 ./
drwxrwxrwx 3 root root 4096 Dec 7 2023 ../
-rwxrwxrwx 1 root root 777 Jul 15 2025 backup.sh*
-rwxrwxrwx 1 root root 552 Mar 3 00:08 backup_with_email.sh*
-rwxrwxrwx 1 root root 106 Jan 4 2024 backup_with_log.sh*
-rwxrwxrwx 1 root root 0 Mar 9 12:00 backuplog.log*