监控并运行脚本

监控并运行脚本

我想要MariaDB监视器monit tools。我的monit script是 :

check process mariadb_pid with pidfile /var/lib/mysql/db1.pid
check program telnet with path "/root/telnet.sh"
   if status eq 99 then exec "/usr/bin/systemctl restart mariadb.service"

并且telnet script是:

#!/bin/bash
cat /root/ips | \
while read host port; do
  result=$(bash -c 'exec 3<> /dev/tcp/'$host'/'$port';echo $?' 2>/dev/null)
  echo $result
 if [ "$result" != "0" ]; then
        exit 99
 fi
done

ips文件是: 192.168.10.10 3306 192.168.10.20 3306 现在,预计如果 ips 文件中的 mariadb ip1 和 ip2 已关闭,则执行

if status eq 99 then exec "/usr/bin/systemctl restart mariadb.service"

但没有跑步。请查看监控日志。

[EST Mar  5 00:34:19] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:34:24] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:34:29] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:34:34] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:34:39] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:34:44] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:34:49] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:34:54] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:34:59] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:35:04] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:35:09] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:35:14] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:35:19] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:35:24] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:35:29] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:35:34] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:35:39] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:35:44] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:35:49] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:35:54] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:36:00] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:36:05] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:36:10] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:36:15] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:36:20] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:36:25] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:36:30] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:36:35] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:36:40] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:36:45] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:36:50] error    : 'telnet' status failed (99) -- 1    
[EST Mar  5 00:36:55] error    : 'telnet' status failed (99) -- 1    

另外,当重新启动 monit 时,该行将首次运行。

[EST Mar  5 00:39:05] error    : 'telnet' status failed (99) -- 1                  
[EST Mar  5 00:39:10] error    : 'telnet' status failed (99) -- 1                  
[EST Mar  5 00:39:15] error    : 'telnet' status failed (99) -- 1                  
[EST Mar  5 00:39:20] error    : 'telnet' status failed (99) -- 1                  
[EST Mar  5 00:39:25] error    : 'telnet' status failed (99) -- 1                  
[EST Mar  5 00:39:26] info     : Reinitializing monit daemon                       
[EST Mar  5 00:39:26] info     : Reinitializing Monit -- control file '/etc/monitrc
[EST Mar  5 00:39:26] info     : 'db1' Monit reloaded                              
[EST Mar  5 00:39:31] error    : 'telnet' status failed (99) -- 1                  
[EST Mar  5 00:39:31] info     : 'telnet' exec: '/usr/bin/systemctl restart mariadb.service'                                                                              
[EST Mar  5 00:39:36] error    : 'telnet' status failed (99) -- 1                  
[EST Mar  5 00:39:41] error    : 'telnet' status failed (99) -- 1                  
[EST Mar  5 00:39:46] error    : 'telnet' status failed (99) -- 1                  
[EST Mar  5 00:39:51] error    : 'telnet' status failed (99) -- 1                  
[EST Mar  5 00:39:56] error    : 'telnet' status failed (99) -- 1                  
[EST Mar  5 00:40:01] error    : 'telnet' status failed (99) -- 1  

有人有这方面的经验吗?

相关内容