Here is the script sqlite_backup.sh under $HOME/:
#! /bin/bash
now=$(date +%d)
echo "Welcome to Sqlite backup script"
sqlite3 /var/www/db/nbhydb.sqlite3 << EOF
.timeout 20000
.backup $HOME/nbhydb_backup_$now.sqlite3
EOF
echo "End of the script"
The script is tested by typing $HOME/sqlite_backup.sh
and there is a backup file created under $HOME. Here is the cron job (crontab -e):
# m h dom mon dow command
5 * * * * $HOME/sqlite_backup.sh
Here is cron log under /var/log/syslog:
Feb 3 13:05:01 ibm-testbox CRON[8961]: (root) CMD ($HOME/sqlite_backup.sh)
The command is scheduled to run at 5th minute of every hour. However there is no backup file generated by the cron job. What we have missed? Thanks.
UPDATE:
cron job is modified to save the the execution error:
5 * * * * $HOME/sqlite_backup.sh > $HOME/backup.log 2>&1
After execution, the log is:
Welcome to Sqlite backup script
End of the script
There is no error at all in the log. However there is still no nbhydb_3_backup.sqlite3 found.
The problem is that
$HOME
variable is not defined in the script. After replacing HOME with absolute path, the script works as it should be.