ssh is not working while calling through expect shell script

Hi,
Please share you experience and way out on below error:-->

#!/bin/bash   -xv
FILE=login.txt
+ FILE=login.txt
CONNECT=sshlogin.exp
+ CONNECT=sshlogin.exp
SERVERNAME=$1
+ SERVERNAME=192.168.12.1
MyServer=""
+ MyServer=
MyUser=""
+ MyUser=
MyPassword=""
+ MyPassword=
exec 3<&0
+ exec
exec 0<$FILE
+ exec
while read line
do
        MyServer=$(echo $line | cut -d'|' -f1)
        MyUser=$(echo $line | cut -d'|' -f2)
        MyPassword=$(echo $line | cut -d'|' -f3)
        if [ "$SERVERNAME" == "$MyServer" ];
        then
           echo "Running ssh $MyUser@$MyServer..."
          $CONNECT $MyPassword $MyServer $MyUser
        fi
done
+ read line
echo $line | cut -d'|' -f1
++ echo '192.168.12.1|dbaguest|password'
++ cut '-d|' -f1
+ MyServer=192.168.12.1
echo $line | cut -d'|' -f2
++ echo '192.168.12.1|dbaguest|password'
++ cut '-d|' -f2
+ MyUser=dbaguest
echo $line | cut -d'|' -f3
++ echo '192.168.12.1|dbaguest|passowrd'
++ cut '-d|' -f3
+ MyPassword=password
+ '[' 192.168.12.1 == 192.168.12.1 ']'
+ echo 'Running ssh dbaguest@192.168.12.1...'
Running ssh dbaguest@192.168.12.1...
+ sshlogin.exp password 192.168.12.1 dbaguest
./sshlogin.sh: sshlogin.exp: command not found
+ read line
exec 0<&3
+ exec
echo "$SERVERNAME not found in login.txt file"
+ echo '192.168.12.1 not found in login.txt file'
192.168.12.1 not found in login.txt file

Regards

hey can you tell us what is the contents of your login.txt file. because your script is not able to take the 192.168.12.1 from your login.txt file.

The problem is because your sh script is not finding your expect script: sshlogin.exp.

Try the following:

CONNECT=<FullPathTo>/sshlogin.exp
# Or
export PATH=${PATH}:<FullPathTo sshlogin.exp>

I hope it helps.

Hi,
Thanks for you reply!! Now this problem got resoved.
Now I am not able to connect remote host using ssh ,however with the same password I am able to connect menually.here I am listing the output.Please give your suggestion.

+ echo dbaguest,192.168.12.1,password
dbaguest,192.168.12.1,password
./test.exp $paswd $newPassword $addr $username
++ ./test.exp password newpassword 192.168.12.1 dbaguest
+ cct=spawn ssh -t dbaguest@192.168.12.1
dbaguest@192.168.12.1's password:
password
Permission denied, please try again.
dbaguest@192.168.12.1's password:
+ [[ spawn ssh -t dbaguest@192.168.12.1
dbaguest@147.149.205.13's password:
password
Permission denied, please try again.
dbaguest@192.168.12.1's password: == *login* ]]
+ [[ spawn ssh -t dbaguest@192.168.12.1
dbaguest@192.168.12.1's password:
password
Permission denied, please try again.
dbaguest@192.168.12.1's password: == *Permission* ]]
+ echo ,192.168.12.1,password
,192.168.12.1,password
+ cct=
+ read line

What is your expect script doing? Can you post it here?

If you are in the box that has the: "autoexpect" command, try to use it to generate a script that suit your needs.

Here is a link to an online autoexpect man pages: Unix man pages: autoexpect (1)

Regards.

I guess you should try to SSH login without password.

Having a password anywhere in a file is a security hole.

I changed all my routines to use ssh public key authentication, and this is an excelent link: OpenSSH Public Key Authentication