我想创建一个shell脚本,首先从多个系统上的文本文件中保存的服务列表中检查服务的状态,然后在执行结束后发送警报邮件。 就像我必须从文本文件中获取输入 1)Ip.txt ="持有不同系统的ip" 2)Services.txt ="它包含服务列表"
这是我的代码:
#!/bin/sh
server_cnt=ip.txt;
serverip= 'cat $server_cnt;
servicename=service.txt;
servicelines= `cat $servicename;
email= 'cat $email.txt'
for i in $serverip
do
for s in $servicelines
do
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "$SERVICE service running, everything is fine"
else
echo "$SERVICE is not running"
echo "$SERVICE is not running!" | mail -s "$SERVICE down" $email
fi
ctr1= `expr ctr1 + 1'
done
ctr2= `expr ctr2 + 1`
done