What to do when cron isn't fast enough
Sometimes you need to automate a task that needs to happen every few seconds rather than minutes or hours. Recently I needed to rsync two directories between servers every few seconds. Normally you would just make a cron job and call it a day, but the requirement of every 3 seconds makes cron inadequate. Any easy solution is to write a script in a loop and make an init.d script to start it or included it in your /etc/rc.local file. Below is a simple example...
#!/bin/bash
while true
do
rsync -azqvr --force /my/dir/ user@host:/my/dir/
sleep 3
done
All thats happening here is we start an endless loop, then use sleep to control the interval in seconds your cmd executes. Pretty simple eh. Post a comment if you know a better way. Thanks!






Comments
Post new comment