如何使用 shell 脚本监控 rstudio-server.status
How to monitor rstudio-server.status using shellscript
我正在尝试使用 bash 脚本监控 rstudio-server.status 并每 5 分钟将其 cron 到 运行 并将服务状态推送到日志文件。但是,不知何故我无法获得服务的状态。
service=rstudio-server.service
if [[ $(systemctl status $service)]] ; then
echo "$service is running !! nothing to worry!"
else
/usr/lib/$service start
fi
这是监控的好方法吗?
很久以前就知道了,现在发布。
谢谢大家!
#!/bin/bash
# Shell-guy to monitor a process (0~0)
#<script.sh> "service_name"
service=
if [ "$(systemctl status $service | grep -c "active (running)")" -gt 0 ];then
echo "$service is running !!"
elif [ "$(systemctl status $service | grep -c "active (running)")" -eq 0 ];then
echo "$service is not running"
$service restart
if [ "$(systemctl status $service | grep -c "active (running)")" -lt 1 ];then
$service restart
elif [ "$(systemctl status $service | grep -c "active (running)")" -eq 0 ];then
echo "The service is not found!!"
fi
fi
我正在尝试使用 bash 脚本监控 rstudio-server.status 并每 5 分钟将其 cron 到 运行 并将服务状态推送到日志文件。但是,不知何故我无法获得服务的状态。
service=rstudio-server.service
if [[ $(systemctl status $service)]] ; then
echo "$service is running !! nothing to worry!"
else
/usr/lib/$service start
fi
这是监控的好方法吗?
很久以前就知道了,现在发布。 谢谢大家!
#!/bin/bash
# Shell-guy to monitor a process (0~0)
#<script.sh> "service_name"
service=
if [ "$(systemctl status $service | grep -c "active (running)")" -gt 0 ];then
echo "$service is running !!"
elif [ "$(systemctl status $service | grep -c "active (running)")" -eq 0 ];then
echo "$service is not running"
$service restart
if [ "$(systemctl status $service | grep -c "active (running)")" -lt 1 ];then
$service restart
elif [ "$(systemctl status $service | grep -c "active (running)")" -eq 0 ];then
echo "The service is not found!!"
fi
fi