Re: Starting a Linux process only if it isn't started
Posted: Mon Apr 22, 2024 10:18 am
Hello @drewdavis,
You can definitely accomplish what you're thinking of using something like the following:
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