Created
December 10, 2018 14:00
-
-
Save coffnix/bffb0a9e85c02455ed0a2484dadfbde5 to your computer and use it in GitHub Desktop.
lock em bash script
This file contains hidden or 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 | |
| ############################################################################### | |
| # Testa se script já encontra-se em execução | |
| test_running() { | |
| RUNNING=$(ps aux | grep "$(printf '%s\n' "${0##*/}")" | grep bash | grep -v "bash -c" | grep -v $$ | grep -v grep | wc -l) | |
| if [ ${RUNNING} -gt 1 ]; then | |
| echo "Script ja esta rodando, aguardando 10 segundos para tentar novamente." | |
| sleep 10 | |
| RUNNING=$(ps aux | grep "$(printf '%s\n' "${0##*/}")" | grep bash | grep -v "bash -c" | grep -v $$ | grep -v grep | wc -l) | |
| if [ ${RUNNING} -gt 1 ]; then | |
| echo "Script ja esta rodando, nao sera executado novamente." | |
| exit 1 | |
| fi | |
| fi | |
| } | |
| test_running | |
| ############################################################################### | |
| # Iniciando script | |
| sleep 30 | |
| ############################################################################### | |
| # Fim do script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment