Created
March 28, 2018 17:31
-
-
Save sxslex/569e012f92bd9a78f1952cb642986959 to your computer and use it in GitHub Desktop.
script bash para controle de execução através de semaforo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Deve ser executado de 15 em 15 minutos | |
# CRONTAB | |
# 0 15,30,45 * * * * script_semaphore.sh > script_semaphore.log 2>&1 | |
echo $(date) | |
DIR=$(dirname $0) | |
PIDFILE=${DIR}"/script_semaphore.pid" | |
PUBLICA=$(dirname $(dirname $(dirname $DIR))) | |
if [ -f ${PIDFILE} ] | |
then | |
PID=$(cat ${PIDFILE}) | |
ps -p ${PID} > /dev/null 2>&1 | |
if [ $? -eq 0 ] | |
then | |
echo "Programa ja esta em execucao: "${PID} | |
exit 1 | |
else | |
echo "PID de arquivo antigo: "${PID} | |
fi | |
fi | |
echo $$ > ${PIDFILE} | |
if [ $? -ne 0 ] | |
then | |
echo "Nao foi possivel criar o arquivo 'script_semaphore.pid'" | |
exit 1 | |
fi | |
cd ${DIR} | |
echo "INICIO" | |
# Codigo do script | |
python -c "import time;time.sleep(30)" | |
echo "FIM" | |
rm ${PIDFILE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment