1

I trying to use the spawn command to connect to remote server, execute some commands/script.

Here is script:

#!/usr/bin/expect
for i in `srvctl status database -d PROD | awk -F " " '{print $(NF)}'`
do
echo "value of i is $i"
spawn ssh "$i"
echo "vijay"
done

Here is output

bash-3.2$ sh a.sh
value of i is prod1
a.sh: line 8: spawn: command not found
vijay
value of i is prod2
a.sh: line 8: spawn: command not found
vijay

I am using RHEL 5.11 .

 bash-3.2$ expect -v
 expect version 5.43.0

Thanks in Advance.

  • public-key ssh authentication is a lot safer and a lot more reliable than a scripted login with expect. – cas Jun 8 '16 at 0:26
2

When you run a script as an argument to shell, like you are doing:

sh a.sh

the shebang will be ignored and the script a.sh will be interpreted by sh. As there is no such command as spawn in your system (spawn is expect specific command), shell is throwing the given error.

Given your shebang is #!/usr/bin/expect, it is not clear what you are trying to do as you have many (all except spawn) non expect specific commands in the script.

  • After referring to few old posts, i have written those commands, If its wrong, then how I can run ssh to remote server and run some commands ? – Vijay Jun 7 '16 at 5:39
  • 1
    @Vijay That goes as a new question i am afraid :) – heemayl Jun 7 '16 at 5:41
  • Posted as new question. – Vijay Jun 7 '16 at 6:48

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.