I am writing a Bash script that is supposed to run other daemonized Bash scripts, called servlets.
The function I am inquiring about is getStatus:
getStatus() { servletToCheck="$@" if [ "$(ps -aux | grep \"$(whoami)\" | grep \"${servletToCheck}\" | grep -v \"grep\" | wc -l)" -eq 0 ]; then echo -n "Offline" else echo -n "Online" fi } What it should be doing is checking if the arguments are a running process owned by the user, and output Online if it is, Offline otherwise.
Now, this function seems to be working perfectly. The problem seems to be with how I'm parsing it:
if [ "$(getStatus ${tbnServlet})" == "Online" ]; then outSuccess "Started servlet: ${tbnServlet}" exit 0 else outWarning "Failed to start servlet: ${tbnServlet}" exit 3 fi Strangely, even when the servlet is up and running, it says it Failed to start/stop servlet, and running a function that lists the servlets lists all of them as offline, even when they aren't.
What is the issue, and how can I correct it?