检查服务状态
#!/bin/bash
PS_C=$(ps -ef |grep httpd |grep -vc grep)
if [ $PS_C -eq 0 ];then
echo "sorry httpd not running" | mail -s "test mail" 17733661341@163.com
fi
首先本机安装好nmap,yum搭建好
#!/bin/bash
for i in 23 24
do
nmap -n -p 22,80,111,53 192.168.30.$i | grep -E "tcp|udp"
done
检测本机IP状态 创建文件iplist 添加IP本机的
#!/bin/bash
for ip in $(cat /root/iplist)
do
ping -c 2 -i 0.2 -w 3 $ip &> /dev/null
if [ $? -eq 0 ]
then
echo "Host $ip is up"
else
echo "Host $ip isdown"
fi
done
检测本机的网段
#!/bin/bash
for ip in 192.168.30.{20..150}
do
ping -c 2 -i 0.2 -w 3 $ip &> /dev/null
if [ $? -eq 0 ]
then
echo "Host $ip is up "
else
echo "Host $ip is down"
fi
done