I have a script where it checks whether a package is installed or not and whether the port 8080 is being used by a particular process or not. I am not experienced at all with bash, so I did something like this:
if dpkg -s net-tools; then
if netstat -tlpn | grep 8080 | grep java; then
echo "Shut down server before executing this script"
exit
fi
else
echo "If the server is running please shut it down before continuing with the execution of this script"
fi
# the rest of the script...
However when the script is executed I get both the dpkg -s net-tools
and the netstat -tlpn | grep 8080 | grep java
outputs in the terminal, and I don't want that, how can I hide the output and just stick with the result of the if
s?
Also, is there a more elegant way to do what I'm doing? And is there a more elegant way to know what process is using the port 8080 (not just if it's being used), if any?