今天重新写一下,这里用的zabbix-agent5.2版本
#!/bin/bash
# zabbix-agent启停脚本
# 示例:./当前脚本名 可选参数[start/stop/restart/status]
# 配置项
# conf 配置文件路径,start启动脚本路径,pid文件存放路径(自定义)
conf=/opt/zabbix-agent5.2/conf/zabbix_agentd.conf
start="/opt/zabbix-agent5.2/sbin/zabbix_agentd"
pid="/tmp/zabbix-agent.pid"
# 主程序
pidcat=`cat $pid`
[ ! -f "$pid" ] && ps aux | egrep "./zabbix_agentd\ -c $conf" | awk '{print $2}' >$pid
if [ "$1" == "start" -o "$1" == "restart" ];then
[ "$1" == "restart" ] && [[ ! "$pidcat" == "" ]] && kill $pidcat && : > $pid
$start -c $conf
ps aux | egrep "./zabbix_agentd\ -c $conf" | awk '{print $2}' >$pid
if [ "$pidcat" == "" ];then
[[ ! "$pidcat" == "" ]] && echo "zabbix-agent started" || echo "zabix-agent start fail"
else
[ "$1" == "restart" ] && echo "zabbix-agent restarted" || echo "zabbix-agent started"
fi
elif [ "$1" == "stop" ];then
[[ ! "$pidcat" == "" ]] && kill $pidcat && : > $pid
echo "zabbix-agent stopped"
elif [ "$1" == "status" ];then
[[ ! "$pidcat" == "" ]] && echo "zabbix-agent started(pid:$pidcat)" || echo "zabbix-agent not started"
else
echo "./zabbix-aget [start/stop/restart/status]"
fi