본문으로 바로가기

Linux system 자동점검 script

category IT/Linux, Unix 2021. 3. 26. 14:38
반응형

#"!"/bin/bash

#jin-hyo, yun (2018.08.14)

 

tmp_fn="temp.tmp"

 

clear

echo

echo "========================================================="

echo " System Check Automation (Create by YJH, 2018/08/14) "

echo "---------------------------------------------------------"

os_ver=`grep . /etc/*centos-release |perl -ane print`

chk_time=`date`

echo " OS Ver : " $os_ver

echo " DB Ver :  MariaDB 10.1.26"

echo " Check  : " $chk_time 

echo "========================================================="

cpu_stat=`sar 1 3 |grep Average |perl -ane 'printf "$F[2]%"'`

mem_stat=`free -h |grep Mem |perl -ane 'printf "$F[2]/$F[1]"'`

swap_stat=`free -h |grep Swap |perl -ane 'printf "$F[2]/$F[1]"'`

echo

echo "+--------------------------------------------------------+"

echo "| 1. System Cehck (CPU, Memory, Swap)                    |"

echo "+--------------------------------------------------------+"

echo " CPU    : " $cpu_stat

echo " MEMORY : " $mem_stat

echo " SWAP   : " $swap_stat

ps_sshd=`ps -ef |grep -v grep |perl -ne 'printf 0 < $.  if /sshd$/'`

ps_crond=`ps -ef |grep -v grep |perl -ne 'printf 0 < $.  if /crond$/'`

echo

echo "+--------------------------------------------------------+"

echo "| 2. File system Usage                                   |"

echo "---------------------------------------------------------+"

df -h | awk 'NR == 1; NR > 1 {print $0 | "sort -k6"}'

disk_stat=`smartctl -H /dev/sda1 |grep 'SMART Health Status' |perl -ane 'printf "$F[3]"'`

echo

echo "+--------------------------------------------------------+"

echo "| 3. Disk Health Status                                  |"

echo "+--------------------------------------------------------+"

echo " SMART Health Status : " $disk_stat

echo 

sys_boot=`who -b | perl -ane print`

echo "+--------------------------------------------------------+"

echo "| 4. System Boot                                         |"

echo "+--------------------------------------------------------+"

echo "" $sys_boot     

uptime

echo

echo "+--------------------------------------------------------+"

echo "| 5. Current login User                                  |"

echo "+--------------------------------------------------------+"

who -u

echo

echo "-------------------- ( End of Check ) --------------------" 

echo

cat /dev/null > $tmp_fn