Check the service count is greater than zero. if yes the service is running and if not start the service.
Code:
#!/bin/bash service=service_that_you_when_to_check if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 )) then echo "$service is running!!!" else /bin/systemctl start $service fi
Let’s put it in the one minute crontab to work automatically.
Code:
* * * * * /bin/sh /PATH/TO/SCRIPT.sh