I am trying to stop tomcat on a remote server using a bash script. Here is the function:
function stop_remote_tomcat () {
CURRENT_SERVER=$1
CURRENT_USER=$2
CURRENT_PEM_FILE=$3
COMMAND="ssh -i $CURRENT_PEM_FILE $CURRENT_USER@$CURRENT_SERVER \"/bin/sh sudo /etc/init.d/tomcat stop\""
echo $COMMAND
$COMMAND
}
Then inside a case statement this function is called.
My problem is if I just copy the output the echo $COMMAND
statement and run it as independent command it works perfectly. But when it is run in the script it gives an error:
sudo /etc/init.d/tomcat stop: No such file or directory
Can somebody please explain how this can be achieved inside a bash script?