Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- log_dir="/var/log"
- logs_ver=( "wtmp" "wtmp.1" "wtmp.2" "wtmp.3" )
- sh="shutdown"
- re="reboot"
- for i in ${logs_ver[@]}; do
- wtmp_logs=$log_dir/$i
- if [ -f "$wtmp_logs" ]; then
- echo "Log for $wtmp_logs"
- if uname -a | grep -i bsd > /dev/null 2>&1;
- then echo "System is *Bsd variant"
- absd=`last -f $wtmp_logs| grep -i -E "$re"|wc -l`
- bbsd=`last -f $wtmp_logs| grep -i -E "$sh"|wc -l`
- if [ $absd -gt $bbsd ]; then
- echo "reboot $absd times > shutdown $bbsd times"
- echo "sumething not right"
- else
- echo "reboot $absd times = shutdown $bbsd times OK"
- fi
- elif uname -a | grep -i linux > /dev/null 2>&1;
- then echo "System is *Linux variant"
- a=`last -a -x -f $wtmp_logs| grep -i -E "$re"|wc -l`
- b=`last -a -x -f $wtmp_logs| grep -i -E "$sh"|wc -l`
- if [ $a -gt $b ]; then
- echo "reboot $a times > shutdown $b times"
- echo "sumething not right"
- else
- echo "reboot $a times = shutdown $b times OK"
- fi
- else
- echo "not found"
- fi
- else
- echo "wtmp log not existed for $wtmp_logs"
- fi
- done
Add Comment
Please, Sign In to add comment