View difference between Paste ID: uNzWyycz and 1BCGcqGW
SHOW: | | - or go back to the newest paste.
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" )
5+
sh="shutdown"
6-
#crash_status=`last -a -x | grep crash`
6+
re="reboot"
7-
#shutdown_status=`last -a -x | grep shutdown`
7+
8-
#status_report=`last -a -x | grep $last_state`
8+
9
        wtmp_logs=$log_dir/$i
10
        if [ -f "$wtmp_logs" ]; then
11
                echo "Log for $wtmp_logs"
12
                        if uname -a | grep -i bsd > /dev/null 2>&1;
13
                                then echo "System is *Bsd variant"
14-
                echo "wtmp log existed $wtmp_logs"
14+
                                        absd=`last -f $wtmp_logs| grep -i -E "$re"|wc -l`
15
                                        bbsd=`last -f $wtmp_logs| grep -i -E "$sh"|wc -l`
16-
                        if last -a -x -f $wtmp_logs| grep "crash";
16+
                                        if [ $absd -gt $bbsd ]; then
17-
                                then echo "Status report is CRASH"
17+
                                                echo "reboot $absd times > shutdown $bbsd times"
18-
                        elif last -a -x -f $wtmp_logs| grep "shutdown";
18+
                                                echo "sumething not right"
19-
                                then echo "Shutdown process detected"
19+
                                        else
20
                                                echo "reboot $absd times = shutdown $bbsd times OK"
21
                                        fi
22
                        elif uname -a | grep -i linux > /dev/null 2>&1;
23
                                then echo "System is *Linux variant"
24
                                        a=`last -a -x -f $wtmp_logs| grep -i -E "$re"|wc -l`
25
                                        b=`last -a -x -f $wtmp_logs| grep -i -E "$sh"|wc -l`
26
                                        if [ $a -gt $b ]; then
27
                                                echo "reboot $a times > shutdown $b times"
28
                                                echo "sumething not right"
29
                                        else
30
                                                echo "reboot $a times = shutdown $b times OK"
31
                                        fi
32
                        else
33
                                echo "not found"
34
                        fi
35
        else
36
                echo "wtmp log not existed for $wtmp_logs"
37
        fi
38
done