Add distribted cron script
This commit is contained in:
commit
d87fb93360
1 changed files with 30 additions and 0 deletions
30
distributed_cron.sh
Normal file
30
distributed_cron.sh
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
TIME=$(shuf -i 0-800 -n1)
|
||||||
|
sleep 0.$TIME
|
||||||
|
echo "Sleep for 0.$TIME"
|
||||||
|
|
||||||
|
echo "Checking cron_lock file"
|
||||||
|
FILE=$1
|
||||||
|
|
||||||
|
if [ ! -f $FILE ]
|
||||||
|
then
|
||||||
|
echo $(hostname) > $FILE
|
||||||
|
echo "Create cron_lock for server"
|
||||||
|
|
||||||
|
$2
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]
|
||||||
|
then
|
||||||
|
echo "FAILED -- $(date) -- $(hostname)" >> $FILE.log
|
||||||
|
else
|
||||||
|
echo "OK -- $(date) -- $(hostname)" >> $FILE.log
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Job done. Keep lock for 30 seconds"
|
||||||
|
sleep 30
|
||||||
|
rm $FILE
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "Other Server is running cron job"
|
||||||
|
exit 0
|
Loading…
Reference in a new issue