Answer the question
In order to leave comments, you need to log in
How to prevent double script execution?
Wrote a simple script for database backup
#!/bin/bash
BACKUP_PATH="/home/backup"
USER="user"
PASS="xxxx"
LOGFILE="/var/log/backup.log"
echo "[--------------------------------[`date +%F--%H-%M`]--------------------------------]" >> $LOGFILE
echo "[----------][`date +%F--%H-%M`] Run the backup script..." >> $LOGFILE
mysqldump -u $USER -p$PASS s11 >> $BACKUP_PATH/s11-`date +%F--%H-%M`.sql
echo "[----------][`date +%F--%H-%M`] done." >> $LOGFILE
exit
Answer the question
In order to leave comments, you need to log in
Run the script via flock :
From the advantages over just creating a lock file and checking it when running the script: the situation when the process was nailed or segfaulted by something, that is, the lock file remained, but the process was not started. In this case, it will not start until you delete the lock file manually.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question