Skip to content

Instantly share code, notes, and snippets.

@Hyunho
Created December 15, 2013 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hyunho/7970582 to your computer and use it in GitHub Desktop.
Save Hyunho/7970582 to your computer and use it in GitHub Desktop.
prevent that two same scripts run concurrently
#!/bin/sh
PIDFILE=/tmp/update_index.pid
if [ -e $PIDFILE ]
then
PID=$(cat $PIDFILE)
PSCNT=$(ps -p $PID | grep -v CMD | wc -l)
if [ $PSCNT -le 0 ]
then
echo "Invalid PID file"
rm -rf $PIDFILE
else
PROCINFO=$(ps --ppid $PID | grep -v CMD)
echo "Another process is running.."
echo $PROCINFO
exit
fi
fi
echo $$ > $PIDFILE
/usr/bin/python /var/www/SearchSource/Market/UpdateIndex.py
rm -rf $PIDFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment