Created
July 16, 2011 02:32
-
-
Save vls/1085926 to your computer and use it in GitHub Desktop.
some common utility functions
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
function log() | |
{ | |
local msg=$1 | |
now=`date "+%Y-%m-%d %H:%M:%S"` | |
i=${#FUNCNAME[@]} | |
lineno=${BASH_LINENO[$i-2]} | |
file=${BASH_SOURCE[$i-1]} | |
echo "${now} ${file}:${lineno} ${msg}" | |
} | |
function check_running() | |
{ | |
if [ $# -ne 1 ]; then | |
log "must specify a pid file" | |
exit 1 | |
fi | |
local pidfile=$1 | |
if [ ! -f $pidfile ]; then | |
touch $pidfile | |
fi | |
ps -p `cat ${pidfile}` > /dev/null | |
if [ $? -eq 0 ]; then | |
log "already running" | |
exit 0 | |
else | |
log "I'm running $$" | |
echo $$ > ${pidfile} | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment