简体   繁体   English

寻找 shell 脚本来监视远程 java 进程并在进程被杀死时发送电子邮件警报

[英]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完毕

cat /tmp/host.txt猫 /tmp/host.txt

192.168.10.13 192.168.10.13
192.168.10.19 192.168.10.19

cat /tmp/process.txt猫/tmp/process.txt

java爪哇
snmp smp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 shell脚本来监视日志中的“单词”,然后终止并重新启动进程 - shell script to monitor a “word” in log, then kill and restart process 使用Python将信号发送到远程进程 - Send signals to remote process with Python 避免在杀死父进程时杀死孩子 - Avoid killing children when parent process is killed 当进程被杀死时,python守护进程线程正在退出 - python daemon thread is exiting when process is killed 杀死python进程时杀死子进程? - kill subprocess when python process is killed? 当 python 进程被杀死时运行 atexit() - Run atexit() when python process is killed Python 在执行将进程作为守护程序运行的 shell 脚本时挂起 - Python hangs when executing a shell script that runs a process as a daemon 用于监视流程和子流程的Python脚本 - Python script to monitor process and sub-processes 如何从我的Shell / Python脚本访问GMail(IMAP电子邮件)下载附加到电子邮件的zip文件并进行处理? - How to access GMail (IMAP Email) from my Shell/Python script to download a zip file attached to an email and process it? 使用伪 tty 启动多个 ssh 会话时输出乱码(当 ssh 断开连接/被杀死时,需要远程进程退出) - Output garbled when launching multiple ssh-sessions with pseudo-tty (need remote process to exit when ssh disconnects/is killed)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM