Expect question

I have an expect script that appears to be working normally however for some reason, the remote side appears to be stripping off the variables from the awk command.

This is the original:

expect \"~]$\"
send \"sed 's/=/ /g;s/,/ /g' /home/file.txt | grep abc | awk '{print $6,$8}'

This is the error message:

~]$ sed 's/=/ /g;s/,/ /g' /home/file.txt | grep abc | awk '{print ,}'
awk: {print ,}
awk:        ^ syntax error
awk: {print ,}
awk:         ^ syntax error
awk: cmd. line:1: {print ,}
awk: cmd. line:1:          ^ unexpected newline or end of string

Any help would greatly be appreciated.

Have you tried enclosing the entire send data in single quotes?

1 Like

Yes, I've tried that, didn't change anything.

Where is /home/file.txt (do you want the local or the remote) and what is in it?

Robin

1 Like

I figured out the answer. The Bash shell was interpreting the variables not as part of the awk command. They needed to be commented out like this, see the awk command example:

expect \"~]$\" send \"sed 's/=/ /g;s/,/ /g' /home/file.txt | grep abc | awk '{print \$6,\$8}'

good exercise. Thanks All!

---------- Post updated at 01:01 PM ---------- Previous update was at 01:00 PM ----------

Also the variables could've been declared in advance but that would've been an extra step.

Why are you programming shell scripts inside expect?!

Use ssh as intended and you will have no need to use expect to automate the shell.

1 Like