I have a simple script as below which checks if fail2ban service is running or not on Ubuntu 18.04:
#!/bin/bash
# Script to check if fail2ban service is running
if pgrep -x "fail2ban" > /dev/null
then
echo "Fail2ban is running"
else
echo "Fail2ban is not running"
fi
I have installed fail2ban in a test VM and is running on the VM. Here is a screenshot of systemctl status
command.
But, when the run the above script, I get the result that "Fail2ban is not running". I am not sure if is with the script. I tried ps aux
command too instead of pgrep
. But, I still get the same result.