Page 1 of 1

Re: Starting a Linux process only if it isn't started

Posted: Mon Apr 22, 2024 10:18 am
by bbahn
Hello @drewdavis,

You can definitely accomplish what you're thinking of using something like the following:

Code: Select all

# Check if Nagios is running with /etc/init.d/nagios status, pgrep, systemctl status, ps aux | grep, etc.

# $? holds the exit status of the last command
if [ $? -ne 0 ]; then
    echo "Nagios is not running. Starting Nagios..."
    /etc/init.d/nagios start
else
    echo "Nagios is already running."
fi