I have a bash script that I am trying to reconfigure to remove some hardcoded values.
The script sets a variable with the content from a heredoc section and that variable is passed through to the remote server via ssh.
#!/bin/bash
FILEREF=${1}
CMDS=$(cat <<HDOC
echo $FILEREF
COUNT=$(timeout 10s egrep -c -m 1 'INFO: Destroying ProtocolHandler \["http-bio-8080"\]' <(tail -n0 -f ~/tomcat/logs/catalina.out))
# removed a load of other stuff for brevity
HDOC
)
#/usr/bin/ssh.exe -t -t -o TCPKeepAlive=yes -o ServerAliveInterval=45 -i "$PRIVATE_KEY_PATH" "$REMOTE_USER"@"$REMOTE_HOST" "$CMDS"
The vars given to the ssh command (under cygwin, hence .exe) are set earlier in the script as params.
The problem I have is that the local machine is attempting to run the command that is assigned to COUNT. I want that to be passed to the remote host as is.
So I could wrap HDOC in "", to prevent parsing of stuff, but then the $FILEREF is sent as a literal string, but I want the value of that variable to be sent.
So I guess I need a way of refactoring this part of the script so I can work in both ways, some commands passed as literal strings to be executed remotely, some I want to pass the value of.
Can you suggest an appropriate refactor?