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.

heemayl
  • 56,300
dbain
  • 77
  • public-key ssh authentication is a lot safer and a lot more reliable than a scripted login with expect. – cas Jun 08 '16 at 00:26

1 Answers1

3

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.

heemayl
  • 56,300