[GRLUG] using flock

signals42 at gmail.com signals42 at gmail.com
Sun Dec 22 15:15:16 EST 2013


Actually, you don't have to manually remove the lock file. See the “trap” statement in bash:


http://www.linuxjournal.com/content/use-bash-trap-statement-cleanup-temporary-files

http://bash.cyberciti.biz/guide/Trap_statement


You can take action when a signal is received, including cleaning up a lock file. It's good practice to use trap to clean up after yourself in scripts.








From: Michael Glaske
Sent: ‎Tuesday‎, ‎December‎ ‎24‎, ‎2013 ‎9‎:‎25‎ ‎AM
To: Mailing List for LUG in greater Grand Rapids, MI area.





Pretty easy to implement in bash or sh..  The only problem is, if you Crtl-C out of it, you'll have to manually remove the lock file.



if [ -f /var/run/script.lock ]; then

     print "Already running..  Exiting"

     exit 1

fi




date > /var/run/script.lock




# put your script here




# at the end

rm -f /var/run/script.lock




On Tue, Dec 24, 2013 at 9:17 AM, Eric Beversluis <ebever at researchintegration.org> wrote:

I've got a backup program on a server that includes a mysqldump once a
day which overwrites the existing sysmyqldump.sql. The script also does
rsync (of zarafa-backup, the mysqldump, and /var/lib/zarafa (the zarafa
attachments file) to an external hard drive. Once a month is also copies
the sysmysqldump.sql that's on the external HDD to a file with that
day's date attached.

The cron is set to run every hour. Right now, mysqldump is finishing at
40 min past the hour (00:40), so I think that when it also tries to make
the copy on the 1st of the month it will run over into the next hour.

As I understand it, the thing to do to prevent the script starting over
before the old one finishes is to use 'flock.'

My question is this: How does cron respond if flock prevents the script
from starting at 01:00? Does it start it when the flock is freed or just
skip that cycle or what?

Thanks.

_______________________________________________
grlug mailing list
grlug at grlug.org
http://shinobu.grlug.org/cgi-bin/mailman/listinfo/grlug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://shinobu.grlug.org/pipermail/grlug/attachments/20131222/6a9e2f8c/attachment.html>


More information about the grlug mailing list