脚本实现多台服务器自动巡检

Posted wanglinyan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了脚本实现多台服务器自动巡检相关的知识,希望对你有一定的参考价值。

 

#! /bin/bash
echo "start running" | tee -a 
LANG=en
set `date`
path="/home/check"
echo "start running" | tee -a  $path/log/$1-$2-$3.log
if [ -d /home/check/result/$1-$2-$3 ];
 then
   echo ‘‘
else
mkdir -p /home/check/result/$1-$2-$3
echo `date +"%Y/%m/%d-%H:%M:%S"` "create " "$1-$2-$3" "directory success "|tee -a $path/log/$1-$2-$3.log
fi
echo `date +"%Y/%m/%d-%H:%M:%S"` "starting reading linuxconfig.txt " |tee -a $path/log/$1-$2-$3.log
cat "$path"/config/linuxconfig.txt| while read line;
do
ip=`echo $line |cut -d ‘=‘ -f2`
echo `date +"%Y/%m/%d-%H:%M:%S"` "check LINUX " $ip " starting " |tee -a $path/log/$1-$2-$3.log
(
sleep 1
#echo account
 echo root

sleep 1
#echo password
 echo root

sleep 3
echo "free -k"
echo ""
echo "df -k"
echo ""

#memory_used_rate
echo "ps -ef| grep java"
echo ""
echo "netstat -an|egrep -n ‘80|22|21|23|9043|9044|45331|45332|39194|19195‘"
echo ""
#echo "ifconfig -a "
echo  "/sbin/ip ad"
echo ""

echo " tail -2000  /var/log/messages | grep -v snmp |grep  -i  error "
echo ""
echo "/bin/dmesg  |grep -i error"
echo ""

echo "top -n1|sed -n ‘1,5p‘"
echo "exit"
echo "/usr/bin/vmstat  1 3"
echo ""

sleep 5
)|telnet $ip >/home/check/result/$1-$2-$3/$ip-$1-$2-$3-$4.txt
echo `date +"%Y/%m/%d-%H:%M:%S"` "check LINUX " $ip " end" |tee -a $path/log/$1-$2-$3.log
echo "" | tee -a $path/log/$1-$2-$3.log
done
echo `date +"%Y/%m/%d-%H:%M:%S"` "end reading linuxconfig.txt  " |tee -a $path/log/$1-$2-$3.log
 
echo `date +"%Y/%m/%d-%H:%M:%S"` "starting reading AIXconfig.txt " | tee -a $path/log/$1-$2-$3.log
cat "$path"/config/AIXconfig.txt| while read line;
do
ip=`echo $line |cut -d ‘=‘ -f2`
echo `date +"%Y/%m/%d-%H:%M:%S"` "check IBM AIX " $ip " starting " |tee -a $path/log/$1-$2-$3.log
(
sleep 1
#echo account
 echo root

sleep 1
#echo password
 echo root
sleep 5
echo ""
#echo "df -k"
 echo "df -g"
echo ""

#memory_used_rate
echo "ps -ef| grep java"
echo ""
echo "netstat -an|egrep -n ‘80|22|21|23|9043|9044|45331|45332|39194|19195‘"
echo ""
echo "ifconfig -a"
echo ""
echo "topas"
echo "exit"
sleep 5
)|telnet $ip >/home/check/result/$1-$2-$3/$ip-$1-$2-$3-$4.txt
echo `date +"%Y/%m/%d-%H:%M:%S"` "check IBM AIX " $ip " end " |tee -a $path/log/$1-$2-$3.log
echo "" | tee -a $path/log/$1-$2-$3.log
done
echo `date +"%Y/%m/%d-%H:%M:%S"` "end reading AIXconfig.txt " | tee -a $path/log/$1-$2-$3.log
zip -r /home/check/result/$1-$2-$3/$1-$2-$3.zip /home/check/result/$1-$2-$3/*
echo "End running "

以上是关于脚本实现多台服务器自动巡检的主要内容,如果未能解决你的问题,请参考以下文章

linux服务器巡检脚本

服务器自动巡检shell脚本

写了个自动巡检多个接口地址的脚本!

shell脚本实现同时管理多台服务器

Linux 如何通过某一台服务器调用执行多台远程服务器上的脚本,结果显示在本地?

shell实现交互式在多台服务器批量执行命令