#!/bin/bash # $# == 4, sonst UNKNOWN, Hilfe und exit 3 if [ $# -ne 4 ] ; then echo "Usage:" echo "./check_users_new -w -c " exit 3 fi # -w -c oder -c -w if [ $1 = -w ] && [ $3 = -c ] ; then W=$2 C=$4 elif [ $1 = -c ] && [ $3 = -w ] ; then W=$4 C=$2 else echo "invalid arguments ... (./check_users_new $1 $2 $3 $4)" echo "Usage:" echo "./check_users_new -w -c " exit 3 fi # $W < $C, sonst UNKNOWN und exit 3 if [ $W -ge $C ] ; then echo "invalid values ... (-w $W >= -c $C)" echo "-w must be lower than -c" exit 3 fi # Nutzerdaten holen USERS=`users | wc -w` INFO=`who | cut -d' ' -f1,12 | tr ' ' @ | tr '\n' ',' | tr -d '()' | rev | cut -c 2- | rev` # $USERS == 0 if [ $USERS -eq 0 ] ; then echo "OK - $USERS - No users|users=$USERS;$W;$C;0;" exit 0 # $USERS < $W elif [ $USERS -lt $W ] ; then echo "OK - $USERS - $INFO|users=$USERS;$W;$C;0;" exit 0 # $USERS < $C elif [ $USERS -lt $C ] ; then echo "WARNING - $USERS - $INFO|users=$USERS;$W;$C;0;" exit 1 # $USERS >= $C else echo "CRITICAL - $USERS - $INFO|users=$USERS;$W;$C;0;" exit 2 fi