今天重新写一下,这里用的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
[[ ! "$pidca