Sponsored Content
Top Forums Shell Programming and Scripting Multiple expect/send statements not working in shell script Post 303012900 by skorada on Monday 12th of February 2018 08:42:40 AM
Old 02-12-2018
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

Code:
#!/bin/bash

expect -c '
spawn sshpass -p "password" ssh -o StrictHostKeyChecking=no user@100.10.100.100 "source .profile && add_ip"

expect "IP Address:"
send "10.10.10.10\r"
expect "Enter IP again:"
send "10.10.10.10\r"
'

Output: ./test.sh

Code:
spawn sshpass -p password ssh -o StrictHostKeyChecking=no user@100.10.100.100 source .profile && add_ip
IP Address: 10.10.10.10
Enter IP again:  ====> EXITS here without entering the IP

This doesnt enter the IP again like expected. Any ideas here?
I would like to do this within my bash script and not write a 2nd expect script.Would appreciate any inputs

I added debug to check

Code:
expect version 5.45
argv[0] = /usr/bin/expect  argv[1] = -d
set argc 0
set argv0 "/usr/bin/expect"
set argv ""
executing commands from command file
spawn sshpass -p password ssh -o StrictHostKeyChecking=no user@100.10.100.100 source .profile && add_ip
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {27493}

expect: does "" (spawn_id exp4) match glob pattern "IP Address:"? no
IP Address:
expect: does "IP Address: " (spawn_id exp4) match glob pattern "IP Address:"? yes
expect: set expect_out(0,string) "IP Address:"
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "IP Address:"
send: sending "10.10.10.10\r" to { exp4 }

expect: does " " (spawn_id exp4) match glob pattern "Enter address again to confirm:"? no
10.10.10.10

expect: does " 10.10.10.10\r\n" (spawn_id exp4) match glob pattern "Enter IP again:"? no
Enter address again to confirm:
expect: does " 10.10.10.10\r\nEnter IP again: " (spawn_id exp4) match glob pattern "Enter IP again:"? yes
expect: set expect_out(0,string) "Enter IP again:"
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) " 10.10.10.10\r\nEnter IP again:"
send: sending "10.10.10.10\r" to { exp4 } . ===> Seems to be sending it here


Last edited by skorada; 02-12-2018 at 10:11 AM.. Reason: added debug
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to send multiple files from the shell script

hi, how to send multiple files from the shell script eg : i have /home/adm/file1 /home/adm/file2 /home/adm/cfg how can i attach these files in the mail ? (1 Reply)
Discussion started by: mail2sant
1 Replies

2. Shell Programming and Scripting

within shell script send expect and if else

Hi I have written one shell script , using that i am able to connect to remote machine but i have to #!/usr/bin/expect -f set address set username set password set OOLpath set dbusername set dbpasswd set tnsname set recdbusername set recdbpasswd set rectnsname spawn ssh... (1 Reply)
Discussion started by: mnmonu
1 Replies

3. Shell Programming and Scripting

within shell script send expect and if else

Hi, I have written one shell script , using that i am able to connect to remote machine but i have to #!/usr/bin/expect -f set address set username set password set OOLpath set dbusername set dbpasswd set tnsname set recdbusername set recdbpasswd set rectnsname spawn ssh... (2 Replies)
Discussion started by: mnmonu
2 Replies

4. Shell Programming and Scripting

Multiple if statements in script and unexpected end of file

Two things... 1) If I have an if statement that is true I want it to exit without running the rest of the file, but if it is false I want it to continue.. I just did if ; then exit else echo "" fi Can that work? I want it to exit if $1 is 0, and if not to continue running the rest of the... (1 Reply)
Discussion started by: glev2005
1 Replies

5. Shell Programming and Scripting

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 +... (6 Replies)
Discussion started by: manish_1678
6 Replies

6. AIX

Send ctrl+C in expect script

Hi, Am trying to transfer file via FTP using expect script from server to client i need to interrupt the file transfer between server and client Please help what should used in expect code.. I used send "ctrl+c\r" expect "Aborted" but that didnt work.. I need what should... (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

7. 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

8. Shell Programming and Scripting

Bash Script: Send files to SFTP using Expect

I have to send few gzipped files from local server to SFTP server. My Server Info Distributor ID: Ubuntu Description: Ubuntu 12.04.4 LTS Release: 12.04 Codename: precise Created a bash script and could able to send files to sftp, but i want to send email if transfer is successful. ... (1 Reply)
Discussion started by: krux_rap
1 Replies

9. Shell Programming and Scripting

Expect script error : send: spawn id exp4 not open

Hi, I am executing a expect script in while loop for doing telnet on list of servers stored in file as below : expect script : #!/usr/bin/expect -f set timeout 20 set ip set port if { == 0} { send_user "Usage: scriptname ip port\n" exit 1 } #exp_internal 1 log_user 0 spawn... (3 Replies)
Discussion started by: omkar.jadhav
3 Replies

10. UNIX for Beginners Questions & Answers

To send ID and Password for each command using expect feature in bash script

Dear Tech Guys, I am trying to send some commands on the local server and it always asks for user name and password after each command. To serve the purpose I am using expect function as follows: #!/usr/bin/expect set timeout 20 spawn "./data1.sh" expect "Please Enter UserName: "... (6 Replies)
Discussion started by: Xtreme
6 Replies
XI(4)							   BSD Kernel Interfaces Manual 						     XI(4)

NAME
xi -- Xircom CreditCard Ethernet device driver SYNOPSIS
xi* at xirc? Configuration of PHYs may also be necessary. See mii(4). DESCRIPTION
The xi driver provides support for the Xircom CreditCard family of PCMCIA Ethernet adapters. Supported cards include: Xircom CreditCard Ethernet II Xircom CreditCard 10/100 Ethernet Xircom RealPort 10/100 Ethernet + Modem (Ethernet function only) Intel EtherExpress Pro/100 Compaq Netelligent 10/100 Cards which should work, but have not been confirmed include: Xircom RealPort Ethernet Xircom RealPort 10/100 Ethernet Some Xircom Ethernet products are supported by the tlp(4) driver. MEDIA SELECTION
Media selection is done using ifconfig(8) using the standard ifmedia(4) mechanism. Refer to those manual pages for more information. SEE ALSO
ifmedia(4), mii(4), netintro(4), pcmcia(4), tlp(4), xirc(4), ifconfig(8) HISTORY
The xi device driver appeared in NetBSD 1.5. BUGS
The driver suffers from poor performance. Even with the 10/100 cards, do not expect more than ~450KB/s. Some 10/100 cards may not autonego- tiate reliably and require manual media selection. The Xircom multifunction cards which contain both Ethernet and modem interfaces are known to have problems. This is due to the card not reporting itself correctly as a multifunction card. BSD
June 1, 2007 BSD
All times are GMT -4. The time now is 02:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy