ssh is not working while calling through expect shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh is not working while calling through expect shell script
# 1  
Old 09-16-2010
ssh is not working while calling through expect shell script

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

Code:
#!/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


Moderator's Comments:
Mod Comment Please use code tags. thank you
# 2  
Old 09-16-2010
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.
# 3  
Old 09-16-2010
The problem is because your sh script is not finding your expect script: sshlogin.exp.

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

I hope it helps.
# 4  
Old 09-17-2010
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
# 5  
Old 09-17-2010
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.
# 6  
Old 09-17-2010
I guess you should try to SSH login without password.

Having a password anywhere in a file is a security hole.
# 7  
Old 09-17-2010
Quote:
Originally Posted by Chirel
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiple expect/send statements not working in shell script

Hi I am trying the following in my bash script which logs into my machine and runs a command. Trying to solve this using expect. The first expect statement is hit and it enters the address "10.10.0.10" but when the second expect statement is hit it exits #!/bin/bash expect -c ' spawn... (2 Replies)
Discussion started by: skorada
2 Replies

2. UNIX for Advanced & Expert Users

Calling expect from shell script which inturn call python

Hi Team, I have to execute a task from my local machine, where i keep my .expect,.sh, .bash and .python scripts .Task are coded in the script and has to be executed at remote machine. for that i used following task ..... SCRIPT 1: cat shell_check.sh read value if then expect... (3 Replies)
Discussion started by: Sivarajan N
3 Replies

3. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

4. Shell Programming and Scripting

expect script inside shell script not working.

Shell Scipt: temp.sh su - <$username> expect pass.exp Expect script: pass.exp #!/usr/bin/expect -f # Login ####################### expect "Password: " send "<$password>\r" it comes up with Password: but doesnt take password passed throguh file. (2 Replies)
Discussion started by: bhavesh.sapra
2 Replies

5. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

6. Shell Programming and Scripting

Calling a function which uses expect from a shells script

Hi all, This is the first time i am using expect. I am trying to call a function with in the shell script. The function will shh to a new server and will pass the password using expect and send. I need help in calling the fuction i am getting follaowing errors... here the script ... (8 Replies)
Discussion started by: firestar
8 Replies

7. Shell Programming and Scripting

Calling Expect Script - Telnet

Hi All, I have an Expect script which logs into Cisco switch, performs a show interface command. I want to read a file of ip addresses which will be passed to the expect script. The script to read the file works, the expect script works on it's own but when i call the 'expect' script from the... (12 Replies)
Discussion started by: trinak96
12 Replies

8. Shell Programming and Scripting

Calling Shell Script from Expect...

Hi there, I need some help regarding the execution of shell script from expect as the method I am trying is giving me error. I wrote an shell program which takes two arguments to telnet to a device and saves the output in a file. Following is the script.... (0 Replies)
Discussion started by: cyberparanoid
0 Replies

9. Shell Programming and Scripting

Calling Expect script in Perl...

I call a EXPECT script from my perl script with machine IP and a FIle. The script logins to the machine and exports the value. The values to be exported or stored in a file. I have close to 10 machines and I have created 10 files and pass the corresponding files in command line, Now I could like... (4 Replies)
Discussion started by: ramkriz
4 Replies

10. Shell Programming and Scripting

Calling an Expect script from a Webpage using PHP

I have a webpage that is in HTML and PHP. In PHP I have tried using exec, system, shell_exec and passthru functions to call an Expect Script file (temp.exp). This Expect file spawns a telnet session that uses "expect/send" commands to retrieve information from an environmental unit (not a normal... (0 Replies)
Discussion started by: CCUSmith
0 Replies
Login or Register to Ask a Question