1

I m using sed inside expect script send command as mentioned below and getting the below error. Please let me know what am I missing here.

set new '"$Backend1Name"'
spawn ssh '"${userid}"'@'"$Backend1Name"'
expect "?*assword:*"
send '"$password\r"'
expect "?*~]# "
#puts [send -i $spawn_id "sed -i 's/\#rpc_address:.*/rpc_address:\ 10.31.201.219/' $file\r"]
send -i $spawn_id "sed -i 's/#rpc_address:.*/rpc_address:\ \$new/' /opt/APG/Databases/Cassandra/Default/conf/cassandra.yaml \r"
expect "?*~]# "

error:
sed: -e expression #1, char 30: unterminated `s' command
  • TCL has a regsub(n) that performs substitutions within TCL... are you trying to rewrite the contents of the *.yaml file? – thrig Jul 8 '17 at 13:49
1

Not quite sure what you're trying to do with this line

set new '"$Backend1Name"'

Single quotes have no special meaning in Tcl/expect: they are literally part of the $new value. The value of the new variable will be: single quote, double quote, value of Backend variable, double quote, single quote. If you have not set the Backend1Name variable in the expect script, then you should be getting an error.

You probably want

  • if you want the remote shell to expand the variable

    set new {"$Backend1Name"}
    
  • if you want the expect script to expand the variable, but you need the double quotes in the value

    set new "\"$Backend1Name\""
    

I question whether you want the literal double quotes around the name to show up in the YAML file.

You might want to have a look at lessons 5&6 of the Tcl tutorial

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.