Zionetrix::Git
Repositories
Help
Report an Issue
check_lock_file
Code
Commits
Branches
Tags
Search
Tree:
deaf1ff
Branches
Tags
master
check_lock_file
check_lock_file
Initial commit
Benjamin Renard
commited
deaf1ff
at 2014-12-08 12:57:03
check_lock_file
Blame
History
Raw
#!/bin/bash # Lock file path LOCK_FILE="" # Lock file valid owner VALID_OWNER="" # WARNING time in hours WARN=12 # Critical time in hours CRIT=24 # Debug mode DEBUG=0 function usage() { echo "Check lock file status" echo echo " -l /path/to/lock.file Path to lock file" echo " -o uid Valid lock file owner (optional)" echo " -w W Exit with WARNING status if lock file" echo " has been created for more than W hours" echo " -c C Exit with CRITICAL status if lock file" echo " has been created for more than C hours" echo " -d Enable debug mode" echo " -h Show this message" } while getopts :l:o:w:c:dh FLAG do [ $DEBUG -eq 1 ] && echo "Parameter $FLAG present. Value : '$OPTARG'" case $FLAG in l) LOCK_FILE=$OPTARG ;; o) VALID_OWNER=$OPTARG ;; w) [ $( echo "$OPTARG"|grep -c -e "^[0-9][0-9]*$" ) -ne 1 ] && echo "Invalid WARNING parameter (-w). Must be an integer" && exit 1 WARN=$OPTARG ;; c) [ $( echo "$OPTARG"|grep -c -e "^[0-9][0-9]*$" ) -ne 1 ] && echo "Invalid CRITICAL parameter (-c). Must be an integer" && exit 1 CRIT=$OPTARG ;; d) DEBUG=1 ;; h) usage exit 0 ;; esac done [ -z "$LOCK_FILE" ] && echo "You must specify the lock file path (-l parameter)." && usage && exit 1 if [ ! -d "$( dirname $LOCK_FILE )" ] then echo "UNKNWON - Lock file's parent directory does not exists." exit 3 fi [ $DEBUG -eq 1 ] && ls -ld "$( dirname $LOCK_FILE )" if [ -f $LOCK_FILE ] then # Check owner if [ ! -z "$VALID_OWNER" -a $( ls -al $LOCK_FILE|awk '{print $3}' ) != "$VALID_OWNER" ] then echo "CRITICAL - Lock file present but not owned by $VALID_OWNER" exit 2 fi T=$( ls -al --time-style=+%s $LOCK_FILE|awk '{print $6}' ) CUR=$( date +%s ) let diff=CUR-T let WARN_TIME=WARN*3600 let CRIT_TIME=CRIT*3600 # CRITICAL if diff > $CRIT if [ $diff -gt $CRIT_TIME ] then echo "CRITICAL - Parser lock file present since more than ${CRIT}h" exit 2 # WARNING if diff > $WARN elif [ $diff -gt $WARN_TIME ] then echo "WARNING - Parser lock file present since more than ${WARN}h" exit 1 else echo "OK - Lock file present since less than ${WARN}h" exit 0 fi else echo 'OK - Lock file not present' exit 0 fi