A quick way to run a database update periodically by crontab
- put a .my.cnf file into your home directory, for example
$ cat ~/.my.cnf
[client]
user=yourDbUserName
password=yourDbPassword
host=yourDbHost
- write a bash script to update the database
#!/bin/bash
set -ex
variable=`TZ="Africa/Abidjan" date '+%Y-%m-%d %H:%M:%S'`
sql="Your SQL statement with ${variable}"
logDir=/data/Logs/`date '+%Y'`/`date '+%m'`
mkdir -p "${logDir}"
echo "${sql}" >> "${logDir}/`date '+%d'`.sql"
mysql -v -v -e "${sql}" >> "${logDir}/`date '+%d'`.result.txt"
- put a line by run crontab -e
the end.