salawank

last-check state

Jan 27th, 2012
72
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2.  
  3. log_dir="/var/log"
  4. logs_ver=( "wtmp" "wtmp.1" "wtmp.2" "wtmp.3" )
  5. #last_state=( "crash" "shutdown" "reboot" )
  6. #crash_status=`last -a -x | grep crash`
  7. #shutdown_status=`last -a -x | grep shutdown`
  8. #status_report=`last -a -x | grep $last_state`
  9.  
  10. for i in ${logs_ver[@]}; do
  11.         wtmp_logs=$log_dir/$i
  12.  
  13.         if [ -f "$wtmp_logs" ]; then
  14.                 echo "wtmp log existed $wtmp_logs"
  15.  
  16.                         if last -a -x -f $wtmp_logs| grep "crash";
  17.                                 then echo "Status report is CRASH"
  18.                         elif last -a -x -f $wtmp_logs| grep "shutdown";
  19.                                 then echo "Shutdown process detected"
  20.                         else
  21.                                 echo "not found"
  22.                         fi
  23.         else
  24.                 echo "wtmp log not existed for $wtmp_logs"
  25.         fi
  26. done
RAW Paste Data