admin 发表于 2022-3-31 09:36:34

os_check_linux

--
#!/bin/sh

#USAGE    : collect linux os info
#AUTHOR   : zhangyu
#VERSION: v1.0
#MODIFIED : 2018 05 10

logdir=/tmp/ht/`date +%y%m%d`
[ ! -d $logdir ] && mkdir -p $logdir&&chmod -R 777 $logdir
echo "The output dir ${logdir} has been created successfully!"
log=$logdir/os_info_`hostname`_`date +%y%m%d%H%M`
index=1
                                                                                                                                       
# run this script use root
[ $(id -u) -gt 0 ] && echo "pleaserun the script with root user! " && exit 1

# sequential title for $log
echo_title(){
                echo >> $log
      echo ======================= `hostname`:${index}. $* >> $log
      let index=$index+1
      echo >> $log
}

# prompt of terminal
echo_back(){
[ $(echo $SHELL|grep bash|wc -l) -eq 1 ]&&{
      echo -n $*
}||{
      echo "$*\c"
}
}
#check release ventor
vendor=$(
        if [ -e /etc/oracle-release ];then cat /etc/oracle-release|head -1
        elif [ -e /etc/redhat-release ];then cat /etc/redhat-release|head -1
        elif [ -e /etc/SuSE-release ];then cat /etc/SuSE-release|head -1
        else echo "Other Release"
        fi
)

#collect ip info
ipaddr=$(
for i in $(ip link | grep BROADCAST | awk -F: '{print $2}');
do
ip add show $i | grep -E "BROADCAST|global"| awk '{print $2}' | tr '\n' ' '
echo
done
)

#collect os base info
base_info(){
echo "OS TYPE   :$(uname -s -i)"
echo "OS VENDOR   :${vendor}"
echo "HOST NAME   :$(hostname)"
echo "CHECK DATE:$(date '+%y_%m_%d %H:%M:%S')"
echo "UP TIME   :$(uptime| awk -F[,] '{print $1}'|sed 's/^ //')"
echo "CPU MODE    :$(grep "model name" /proc/cpuinfo|sort -u |awk -F[:] '{print $2}'|sed 's/^ //')"
echo "CPU COUNT   :$(grep "processor" /proc/cpuinfo|wc -l)"
echo "PHY MEM PCT :$(free -m|grep Mem|awk '{print $2,$3,$4}') MB"
echo "SWAP EMM PCT:$(free -m | grep Swap|awk '{print $2,$3,$4}') MB"
echo "LOCALE      :$(locale|grep LANG|awk -F[=] '{print $2}')"
echo "TIME ZONE   :$(date +%Z%z)"

echo_title hostname info
cat /etc/hosts|grep -v ^#|grep -v ^$

echo_title memory nd swap info
grep MemTotal /proc/meminfo
grep SwapTotal /proc/meminfo
echo
free -m

echo_title ip info
echo "${ipaddr}"
echo
ifconfig -a

echo_title usage nd mount info
df -h
echo
lsblk

echo_title user info
cat /etc/shadow

echo_title group info
cat /etc/group

echo_title firewall nd selinux info
systemctl status firewalld
service iptables status
echo "selinux:`getenforce`"

echo_title crontab info
crontab -l>/dev/null 2>&1
if [ $? -eq 0 ];then
        crontab -l | grep -v ^$ | grep -v ^#
fi

echo_title sysctl info
cat /etc/sysctl.conf| grep -v ^#|grep -v ^$

echo_title security limits
cat /etc/security/limits.conf| grep -v ^#|grep -v ^$
grep -v ^# /etc/security/limits.d/*.conf|grep -v ^$

echo_title processes tree
pstree -a -A -c -l -n -p -u -U

echo_title port info
netstat -anlp|grep tcp|grep -E "ora|postgres|asm|mysql|maria|oninit|sybase|httpd"|grep -v tcp6

echo_title vmstat info
vmstat 2 10

echo_title dmesg
tail -100 /var/log/messages
}

echo_back Start to collecting information ...
echo
echo_title os base info
base_info >> $log

echo "OK!completed.see the log file:$log"




页: [1]
查看完整版本: os_check_linux