Script using SSH with expect command

Hi all,

I want to connect to some host with "ssh". I have googled and got some commands of "expect" and "spawn". I was not aware of these commands and tried below script.

$ cat auto.sh
set host xx.xx.xx.xx
set password abcd@1234
set user root
spawn ssh $user@$host
expect "*?assword:*" { send -- "$password\r" }
send -- "\r"
expect eof

But getting the below error

./auto.sh: line 6: spawn: command not found
couldn't read file "*?assword:*": no such file or directory
./auto.sh: line 8: send: command not found
couldn't read file "eof": no such file or directory

Please let me know the errors in the script.

$ echo $SHELL
/bin/bash

Thanks..

is your shebang line is like below ?

#!/usr/bin/expect

---------- Post updated at 12:44 PM ---------- Previous update was at 12:42 PM ----------

But always dont hardcode the password.

google it "password less ssh"

#!/bin/bash

i dont know much about expect

Hope the below link helps for u ( check the shebang line)
SSH login expect shell script to supply username and password

From the above link only, I got some idea..
Any how thanks for the suggestion.