以snmpd进程为例,以下脚本检查进程状态是否为running,如果不是则重新启动进程。
#!/bin/bash
SNMPD=`systemctl status snmpd | grep Active | awk '{print $3}' | cut -d "(" -f2 | cut -d ")" -f1`
if [ "$SNMPD" == "running" ]
then
echo "snmpd service is running..."
else
systemctl restart snmpd
fi