-1

We are having a password which is bt67nJuse3?{]=_0!\`fr,./&##@ (Except the quotes). This password contains characters such as {, `, /, ., ! which might need to be escaped. A lot of combinations have been tried to no avail and after spending a lot of time trying to fix this issue, the following snippet is not working.

Already tried:

  • 'bt67nJuse3?{]=_0!`fr,./&##@'"\r"
  • "bt67nJuse3?{]=_0!`fr,./&##@\r"
  • "bt67nJuse3?{]=_0"'!'"`fr,./&##@\r"
  • 'bt67nJuse3?{]=_0!`fr,./&##@\r'
  • "bt67nJuse3?{]=_0!\`fr,./&##@\r"
  • "bt67nJuse3?{]=_0!\`fr,./&##@\r"

Start of Code:

#!/bin/bash
/usr/bin/expect << EOF
spawn scp user111@servername.domain.com:/home/path1/test1.log /home/path2/
expect {
    " password: " { send 'bt67nJuse3?{]=_0!`fr,./&##@'"\r";  exp_continue }
    eof
}
... some code ...
EOF

How can I get this password into expect?

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
BejoyM
  • 63
  • 8
  • Escape backticks with \. – Socowi Dec 11 '18 at 10:33
  • Not working with "bt67nJuse3?{]=_0!\`fr,./#@\r" missing close-brace while executing "expect { " password: " { send "bt67nJuse3?{]=_0!`fr,./#@\r"; exp_continue } eof } " – BejoyM Dec 11 '18 at 10:37
  • try declaring the password first, with set password "bt67nJuse3?{]=_0!`fr,./#@"; and then send "$password\r" – ralz Dec 11 '18 at 10:41
  • 1
    the problem may be due to quote missing arround bash here-doc delimiter EOF compare `cat <<'EOF'` and `cat < – Nahuel Fouilleul Dec 11 '18 at 10:50
  • I tried this and use \` for "`" and it pasted the wrong password set password "bt67nJuse3?{]=_0!`fr,./#@"; send "$password\r" – BejoyM Dec 11 '18 at 10:53
  • take a look at [sexpect (Expect for Shells)](https://github.com/clarkwang/sexpect) with which you can write *Expect* scripts with **shell code only**. – pynexj Dec 11 '18 at 13:01
  • Stack Overflow is a site for programming and development questions. – jww Dec 13 '18 at 10:03

2 Answers2

0

Making this as a seperate file and using expect command worked:

set password "bt67nJuse3?{]=_0!\`fr,./&##@";
spawn scp user111@servername.domain.com:/home/path1/test1.log /home/path2/
expect {
    " password: " { send "$password\r";  exp_continue }
    eof
}

and Using "expect fileName" worked!!! WOW OMG

BejoyM
  • 63
  • 8
-1

First line

/usr/bin/expect << EOF

must be changed to

/usr/bin/expect << 'EOF'

The main issue is due to how bash process here-doc

      <<[-]word
                  here-document
          delimiter

  ...  If any characters in word are quoted, the delimiter is
  the result of quote removal on word, and the lines in the here-document are not expanded.  If word is unquoted, all lines of the here-document are subjected to parameter  expansion,
   command substitution, and arithmetic expansion, the character sequence \<newline> is ignored, and \ must be used to quote the characters \, $, and `.
Nahuel Fouilleul
  • 18,726
  • 2
  • 31
  • 36
  • @BejoyM, please note that single quotes have no meaning in Tcl: they are just plain characters. use `{braces}` in Tcl -- they have the same purpose as shell single quotes: grouping of words without interpolation. – glenn jackman Dec 11 '18 at 18:12