I am using a bash script to see if the given processes are running. If they are not running then it prints Process `$p' is not running. However, if ALL processes are running I want it to print: "Processes are running" only once.
But the problem is that it prints out "Processes are running" multiple times and it is printed out even though there are processes which are not running. I think something is wrong with the For Loop.
#!/bin/bash
check_process=( "ssh" "mysql" "python" )
for p in "${check_process[@]}"; do
if ! pgrep -x "$p" > /dev/null; then
echo "Process \`$p' is not running"
else
echo "Processes are running"
fi
done