I need to run the following command in a bash script.
The command needs to be run inside a GNU screen so I can see the progress. So the command needs to be in quotes, but because of that I am having problems with the syntax and the code isn't running properly.
I have a file in a remote server called textfile.txt
. It looks like this.
The command gawk command runs fine on its own.
test-server-name 1
test-server-name 2
test-server-name 3
...
test-server-name 23
test-server-name 24
...
I run a screen command together with an ssh command that runs a gawk command to modify a line in the text file, in this case, it should look for test-server-name-1
and add a 0
next to it like this.
test-server-name 1 0
test-server-name 2
test-server-name 3
...
test-server-name 23
test-server-name 24
...
This is what my script looks like in my local server.
localhostname='test-server-name-1'
counter=1
function='textfile'
screen -dmS $counter "ssh -i ~/.ssh/ssh-key username@masteripaddress 'gawk -i inplace -v n='0' -v s='${localhostname}-${function}' '$1 == s { $2 = n } 1' /home/master/Documents/${function}.txt';exec bash;"
But when I run it, the script runs, and I get this error in the attached screen,
gawk: cmd. line:1: ==
gawk: cmd. line:1: ^ syntax error
How do I fix it? What characters need to be escaped