0

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.

user938363
  • 385
  • 2
  • 6
  • 18
  • 1
    [Set up local mail](http://askubuntu.com/questions/2261/how-are-administrators-supposed-to-read-roots-mail) (unfortunately, Ubuntu doesn't do it properly by default). Cron sends you a mail when a job produces error messages. Once you have local mail set up, post the errors produced by this job (if they aren't enough to solve the problem on your own). – Gilles 'SO- stop being evil' Feb 03 '14 at 18:02
  • Does cron keep a log file? – user938363 Feb 03 '14 at 19:27
  • No, no log file (except log entries in `/var/log/auth.log` that let you know that the job ran). Job output is sent as email. – Gilles 'SO- stop being evil' Feb 03 '14 at 19:30
  • Is it possible to save the execution of cron job into a file for late review? Setup email is not trivial job. – user938363 Feb 04 '14 at 03:25

1 Answers1

1

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.

Anwar
  • 75,875
  • 31
  • 191
  • 309
user938363
  • 385
  • 2
  • 6
  • 18