1

Im trying to run my bash script inside an expect script but getting errors.

/usr/bin/expect <<EOD
spawn ssh nginubud@10.123.25.83 $(< try1.sh)
expect "assword:"
send "$reg\r"
expect eof
EOD

im trying to do this in expect ssh nginubud@10.123.25.83 "$(< try1.sh)", this one is working but i need to find a way to run it in automated way. I dont want to use RSA keys.

error that in encountered:

spawn ssh nginubud@10.123.25.83 #tats script
invalid command name "echo"
    while executing
"echo "Enter Year:""

Also i can run my expect ssh script but when i include and try to run my $(< try1.sh) im getting "no variable errors"

pynexj
  • 19,215
  • 5
  • 38
  • 56
  • [Reference](http://stackoverflow.com/questions/4780893/use-expect-in-bash-script-to-provide-password-to-ssh-command) – thar45 Aug 20 '16 at 04:45
  • `#!/bin/bash /usr/bin/expect -c 'expect "\n" { eval spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no usr@$myhost.example.com; interact }' ` how can I insert this line (ssh nginubud@10.123.25.83 "$(< try1.sh)" ). Im trying to run the try1.sh script from machine 1 to remote machine 2. – Jerald Valmoria Aug 20 '16 at 05:12

1 Answers1

0

You can use ssh user@host bash -c .... For example:

[bash] % cat foo.sh
export CMD=$( printf '%q' "$(< try.sh)" )
expect << EOF
spawn ssh foo@localhost bash -c \$::env(CMD)
expect -nocase password:
send bar\r
expect eof
EOF
[bash] % cat try.sh
echo hello world | tr a-z A-Z
[bash] % bash foo.sh
spawn ssh foo@localhost bash -c echo\ hello\ world\ \|\ tr\ a-z\ A-Z
foo@localhost's password:
HELLO WORLD
[bash] %
pynexj
  • 19,215
  • 5
  • 38
  • 56
  • Thanks sir. this is a working method but my script has some input and i cant input anything, script run thru without a prompt of input `Enter Year: Number of Entered Days : echo Details : Year: Month Days echo "Enter Month:" echo "How many days?" Please wait while generating output . . . done !` – Jerald Valmoria Aug 22 '16 at 14:17
  • Hi Sir it only prompt the first input then `Enter Year: 2015 [bash]$ 2015 -bash: 2015: command not found` – Jerald Valmoria Aug 23 '16 at 15:38
  • Please provide more details (your scripts, error messages, debug output, ...). Open a new question if it's not easy to put in the comments. – pynexj Aug 23 '16 at 15:47