I'm trying to write a for loop with grep. When grep returns a value I want to display the message "running". If no value is returned then display "available".
I think there is something is wrong with my if statement, but I can't find anything.
Any suggestions would be greatly appreciated.
#!/bin/sh
#JWR1.0, REL1.10
echo "Content-type: text/html"
echo ""
chk_port = 'ps -ef | grep "port $i -"'
for (( i=1; i<=5; i++ ))
do
if [[ $chk_port ]]; then
echo "Running - $i<br>"
else
echo "Available - $i<br>"
fi
done
echo "<br>"
# For debugging
ps -ef | grep "port 1 -"
Sample output:
Available - 1
Available - 2
Available - 3
Available - 4
Available - 5
apache 7706 7700 0 15:07 ? 00:00:00 grep port 1 -
for-loop rather pointless, since it just checks five times to see if the process was originally running . . .chk_portto$(ps -ef | grep "port $i -"), you're suggesting to dispense with$chk_portand instead use$(ps -ef | grep "port $i -"). O.K., yes, good. :-)