I'm trying to monitor the rstudio-server.status using a bash script and cron it to run every 5minutes and push the status of the service to a logfile. But, somehow i'm unable to get the status of the service.
service=rstudio-server.service
if [[ $(systemctl status $service)]] ; then
echo "$service is running !! nothing to worry!"
else
/usr/lib/$service start
fi
is this a goodway to monitor?
got it a long back ago, posting it now. Thank you all!
#!/bin/bash
# Shell-guy to monitor a process (0~0)
#<script.sh> "service_name"
service=$1
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.