[英]looking for shell script to monitor the remote java process and send an email alert when process got killed
I am looking for a shell script which can ssh to multiple servers and grep the required process and send an email alert if it is not running .我正在寻找一个 shell 脚本,它可以通过 ssh 连接到多个服务器并 grep 所需的进程并在它没有运行时发送电子邮件警报。
I have 10 servers to monitor from the host and each server is having 8 applications running.我有 10 台服务器要从主机监控,每台服务器运行 8 个应用程序。 Is that possible to setup the alert.是否可以设置警报。 I am on CEntos 7我在 Centos 7
Appreciate the earliest response !!感谢第一时间回复!!
Thanks in advance !!提前致谢 !!
#!/bin/bash #!/bin/bash
for host in $(cat /tmp/host.txt)用于 $(cat /tmp/host.txt) 中的主机
do做
echo -n > /tmp/$host.txt echo -n > /tmp/$host.txt
for process in $(cat /tmp/process.txt)用于 $(cat /tmp/process.txt) 中的进程
do做
ssh $host "ps ax | grep $process | grep -v grep" > /tmp/$host.txt ssh $host "ps ax | grep $process | grep -v grep" > /tmp/$host.txt
if [[ -s /tmp/$host.txt ]] ;如果 [[ -s /tmp/$host.txt ]] ; then然后
echo $process is running in $host echo $process 正在 $host 中运行
else别的
echo $process is not running in $host echo $process 不在 $host 中运行
sendEmail -f -t -u "Subject" -l /var/log/sendEmail -o message-content-type=auto -m "" -s -xu -xp sendEmail -f -t -u "主题" -l /var/log/sendEmail -o message-content-type=auto -m "" -s -xu -xp
fi ;菲;
done完毕
done完毕
192.168.10.13 192.168.10.13
192.168.10.19 192.168.10.19
java爪哇
snmp smp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.