shell脚本判断nginx安装和运行
脚本内容:
传入服务名称:
read -p "请输入要判断的程序名称:" service_name
查看服务进程:
count=`ps -aux | grep -cw $service_name`
判断nginx是否安装(系统中是否有nginx命令)
if [ command -v $service_name &>/dev/null ]
thenecho "$service_name 已安装"mkdir -p /wwwecho this is a > /www/index.htmlsystemctl restart $service_nameecho "服务已重启"
elseecho "$service_name未安装,请开始安装"dnf install $service_name -yecho "安装完成"
fi
判断nginx运行状况:
if [ $count -gt 1 ]
thenecho $service_name服务已运行
elseecho $service_name服务未运行cat /etc/nginx/nginx.conf
fi