I have a bash script wrapped in " " so I need to use ' ' for my grep command but it doesn't work. I can't switch the quotes because then the variables are not expanded.
#!/bin/bash PWD=`pwd` source "$PWD/AWS.config.sh" SCRIPT=" cd ~/$APP_PATH; netstat -ln | grep ':80 ' &> /dev/null; if [ $? -eq 0 ]; then echo something on 80; else echo nothing on 80; fi " ssh -i $EC2_PEM_FILE $APP_HOST $SCRIPT
netstat -ln | grep ':anyporthere ' &> /dev/null;
always seems to return $? as 0 suggesting a match when there clearly is none.
As I mentioned if I switch to " " and ' ' for the enclosing script, it works but then the script variables are not expanded which is a problem.