LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-25-2007, 11:15 AM   #1
mallarj
LQ Newbie
 
Registered: Oct 2003
Posts: 6

Rep: Reputation: 0
Expect script to log in to server no longer working - fork broken??


I use an expect script to log in to my office VPN. I've been using this script for quite some time now, and it's worked perfectly. Up until this past week, I've been using Fedora Core 4, and over the weekend I upgraded to Fedora Core 6, and now my script doesn't work. In particular the forking seems to cause the script to fail.

I'm currently using expect version 5.43.0 under "Linux mark 2.6.20-1.2944.fc6 #1 SMP Tue Apr 10 18:46:45 EDT 2007 i686 i686 i386 GNU/Linux"


Here's my script (edited for brevity):

Code:
log_file -a vpn.out
exp_internal 1
log_user 1

set pw [lrange $argv 0 0]
puts $pw

# if {[fork]} exit
# disconnect

spawn vpnclient connect myprofile

expect "Enter Username and Password."
expect "Username"
send mallarj\r

expect "Password"
send $pw\r

expect "Do you wish to continue?"
send y\r

expect "VPN tunnel info"
expect "Client address: "
expect \r

set myip "$expect_out(buffer)"
set myip [string trimright "$myip" "\""]
set myip [string trimright "$myip" "\r"]
set myip [string trimright "$myip" "\n"]

puts "IP: $myip"

exit 0
Here's the normal output from my VPN server:

Code:
/root:vpnclient connect myprofile
Cisco Systems VPN Client Version 4.8.00 (0490)
Copyright (C) 1998-2005 Cisco Systems, Inc. All Rights Reserved.
Client Type(s): Linux
Running on: Linux 2.6.20-1.2944.fc6 #1 SMP Tue Apr 10 18:46:45 EDT 2007 i686
Config file directory: /etc/opt/cisco-vpnclient

Initializing the VPN connection.
Initiating TCP to XX.XXX.XXX.XX, port 443
Contacting the gateway at XX.XXX.XXX.XX
User Authentication for myprofile...

Enter Username and Password.

Username [mallarj]: mallarj
Password []:
Authenticating user.
Negotiating security policies.
Securing communication channel.

You have connected to the XXX Server.  Unauthorized use of this system is prohibited.

Do you wish to continue? (y/n): y

Your VPN connection is secure.

VPN tunnel information.
Client address: YY.YYY.YYY.YYY
Server address: XX.XXX.XXX.XX
Encryption: 168-bit 3-DES
Authentication: HMAC-MD5
IP Compression: None
NAT passthrough is active on port TCP 443
Local LAN Access is disabled
When I run the script as is, it works fine. Here's the output:

Code:
parent: waiting for sync byte

parent: telling child to go ahead

parent: now unsynchronized from child

spawn: returns {28735}



expect: does "" (spawn_id exp7) match glob pattern "Enter Username and Password."? no

Cisco Systems VPN Client Version 4.8.00 (0490)



expect: does "Cisco Systems VPN Client Version 4.8.00 (0490)\r\n" (spawn_id exp7) match glob pattern "Enter Username and Password."? no

Copyright (C) 1998-2005 Cisco Systems, Inc. All Rights Reserved.



expect: does "Cisco Systems VPN Client Version 4.8.00 (0490)\r\nCopyright (C) 1998-2005 Cisco Systems, Inc. All Rights Reserved.\r\n" (spawn_id exp7) match glob pattern "Enter Username and Password."? no

Client Type(s): Linux



expect: does "Cisco Systems VPN Client Version 4.8.00 (0490)\r\nCopyright (C) 1998-2005 Cisco Systems, Inc. All Rights Reserved.\r\nClient Type(s): Linux\r\n" (spawn_id exp7) match glob pattern "Enter Username and Password."? no

Running on: Linux 2.6.20-1.2944.fc6 #1 SMP Tue Apr 10 18:46:45 EDT 2007 i686



expect: does "Cisco Systems VPN Client Version 4.8.00 (0490)\r\nCopyright (C) 1998-2005 Cisco Systems, Inc. All Rights Reserved.\r\nClient Type(s): Linux\r\nRunning on: Linux 2.6.20-1.2944.fc6 #1 SMP Tue Apr 10 18:46:45 EDT 2007 i686\r\n" (spawn_id exp7) match glob pattern "Enter Username and Password."? no

Config file directory: /etc/opt/cisco-vpnclient





expect: does "Cisco Systems VPN Client Version 4.8.00 (0490)\r\nCopyright (C) 1998-2005 Cisco Systems, Inc. All Rights Reserved.\r\nClient Type(s): Linux\r\nRunning on: Linux 2.6.20-1.2944.fc6 #1 SMP Tue Apr 10 18:46:45 EDT 2007 i686\r\nConfig file directory: /etc/opt/cisco-vpnclient\r\n\r\n" (spawn_id exp7) match glob pattern "Enter Username and Password."? no

Initializing the VPN connection.



expect: does "Cisco Systems VPN Client Version 4.8.00 (0490)\r\nCopyright (C) 1998-2005 Cisco Systems, Inc. All Rights Reserved.\r\nClient Type(s): Linux\r\nRunning on: Linux 2.6.20-1.2944.fc6 #1 SMP Tue Apr 10 18:46:45 EDT 2007 i686\r\nConfig file directory: /etc/opt/cisco-vpnclient\r\n\r\nInitializing the VPN connection.\r\n" (spawn_id exp7) match glob pattern "Enter Username and Password."? no

Initiating TCP to XX.XXX.XXX.XX, port 443



expect: does "Cisco Systems VPN Client Version 4.8.00 (0490)\r\nCopyright (C) 1998-2005 Cisco Systems, Inc. All Rights Reserved.\r\nClient Type(s): Linux\r\nRunning on: Linux 2.6.20-1.2944.fc6 #1 SMP Tue Apr 10 18:46:45 EDT 2007 i686\r\nConfig file directory: /etc/opt/cisco-vpnclient\r\n\r\nInitializing the VPN connection.\r\nInitiating TCP to XX.XXX.XXX.XX, port 443\r\n" (spawn_id exp7) match glob pattern "Enter Username and Password."? no

Contacting the gateway at XX.XXX.XXX.XX



expect: does "Cisco Systems VPN Client Version 4.8.00 (0490)\r\nCopyright (C) 1998-2005 Cisco Systems, Inc. All Rights Reserved.\r\nClient Type(s): Linux\r\nRunning on: Linux 2.6.20-1.2944.fc6 #1 SMP Tue Apr 10 18:46:45 EDT 2007 i686\r\nConfig file directory: /etc/opt/cisco-vpnclient\r\n\r\nInitializing the VPN connection.\r\nInitiating TCP to XX.XXX.XXX.XX, port 443\r\nContacting the gateway at XX.XXX.XXX.XX\r\n" (spawn_id exp7) match glob pattern "Enter Username and Password."? no

User Authentication for myprofile...



Enter Username and Password.



Username [mallarj]: 

expect: does "Cisco Systems VPN Client Version 4.8.00 (0490)\r\nCopyright (C) 1998-2005 Cisco Systems, Inc. All Rights Reserved.\r\nClient Type(s): Linux\r\nRunning on: Linux 2.6.20-1.2944.fc6 #1 SMP Tue Apr 10 18:46:45 EDT 2007 i686\r\nConfig file directory: /etc/opt/cisco-vpnclient\r\n\r\nInitializing the VPN connection.\r\nInitiating TCP to XX.XXX.XXX.XX, port 443\r\nContacting the gateway at XX.XXX.XXX.XX\r\nUser Authentication for myprofile...\r\n\r\nEnter Username and Password.\r\n\r\nUsername [mallarj]: " (spawn_id exp7) match glob pattern "Enter Username and Password."? yes

expect: set expect_out(0,string) "Enter Username and Password."

expect: set expect_out(spawn_id) "exp7"

expect: set expect_out(buffer) "Cisco Systems VPN Client Version 4.8.00 (0490)\r\nCopyright (C) 1998-2005 Cisco Systems, Inc. All Rights Reserved.\r\nClient Type(s): Linux\r\nRunning on: Linux 2.6.20-1.2944.fc6 #1 SMP Tue Apr 10 18:46:45 EDT 2007 i686\r\nConfig file directory: /etc/opt/cisco-vpnclient\r\n\r\nInitializing the VPN connection.\r\nInitiating TCP to XX.XXX.XXX.XX, port 443\r\nContacting the gateway at XX.XXX.XXX.XX\r\nUser Authentication for myprofile...\r\n\r\nEnter Username and Password."



expect: does "\r\n\r\nUsername [mallarj]: " (spawn_id exp7) match glob pattern "Username"? yes

expect: set expect_out(0,string) "Username"

expect: set expect_out(spawn_id) "exp7"

expect: set expect_out(buffer) "\r\n\r\nUsername"

send: sending "mallarj\r" to { exp7 }



expect: does " [mallarj]: " (spawn_id exp7) match glob pattern "Password"? no

mallarj

Password []: 

expect: does " [mallarj]: mallarj\r\nPassword []: " (spawn_id exp7) match glob pattern "Password"? yes

expect: set expect_out(0,string) "Password"

expect: set expect_out(spawn_id) "exp7"

expect: set expect_out(buffer) " [mallarj]: mallarj\r\nPassword"

send: sending "PASSWORD\r" to { exp7 }



expect: does " []: " (spawn_id exp7) match glob pattern "Do you wish to continue?"? no



Authenticating user.



expect: does " []: \r\nAuthenticating user.\r\n" (spawn_id exp7) match glob pattern "Do you wish to continue?"? no

Negotiating security policies.



expect: does " []: \r\nAuthenticating user.\r\nNegotiating security policies.\r\n" (spawn_id exp7) match glob pattern "Do you wish to continue?"? no

Securing communication channel.



expect: does " []: \r\nAuthenticating user.\r\nNegotiating security policies.\r\nSecuring communication channel.\r\n" (spawn_id exp7) match glob pattern "Do you wish to continue?"? no





expect: does " []: \r\nAuthenticating user.\r\nNegotiating security policies.\r\nSecuring communication channel.\r\n\r\n" (spawn_id exp7) match glob pattern "Do you wish to continue?"? no

You have connected to the XXXXX Server.  Unauthorized use of this system is prohibited.




Do you wish to continue? (y/n): 

expect: does " []: \r\nAuthenticating user.\r\nNegotiating security policies.\r\nSecuring communication channel.\r\n\r\nYou have connected to the XXXXX Server.  Unauthorized use of this system is prohibited.\r\r\n\r\nDo you wish to continue? (y/n): " (spawn_id exp7) match glob pattern "Do you wish to continue?"? yes

expect: set expect_out(0,string) "Do you wish to continue?"

expect: set expect_out(spawn_id) "exp7"

expect: set expect_out(buffer) " []: \r\nAuthenticating user.\r\nNegotiating security policies.\r\nSecuring communication channel.\r\n\r\nYou have connected to the XXXXX Server.  Unauthorized use of this system is prohibited.\r\r\n\r\nDo you wish to continue?"

send: sending "y\r" to { exp7 }



expect: does " (y/n): " (spawn_id exp7) match glob pattern "VPN tunnel info"? no

y



Your VPN connection is secure.





expect: does " (y/n): y\r\n\r\nYour VPN connection is secure.\r\n\r\n" (spawn_id exp7) match glob pattern "VPN tunnel info"? no

VPN tunnel information.

Client address: YY.YYY.YYY.YYY

Server address: XX.XXX.XXX.XX

Encryption: 168-bit 3-DES

Authentication: HMAC-MD5

IP Compression: None

NAT passthrough is active on port TCP 443

Local LAN Access is disabled





expect: does " (y/n): y\r\n\r\nYour VPN connection is secure.\r\n\r\nVPN tunnel information.\r\nClient address: YY.YYY.YYY.YYY\r\nServer address: XX.XXX.XXX.XX\r\nEncryption: 168-bit 3-DES\r\nAuthentication: HMAC-MD5\r\nIP Compression: None\r\nNAT passthrough is active on port TCP 443\r\nLocal LAN Access is disabled\r\n\r\n" (spawn_id exp7) match glob pattern "VPN tunnel info"? yes

expect: set expect_out(0,string) "VPN tunnel info"

expect: set expect_out(spawn_id) "exp7"

expect: set expect_out(buffer) " (y/n): y\r\n\r\nYour VPN connection is secure.\r\n\r\nVPN tunnel info"



expect: does "rmation.\r\nClient address: YY.YYY.YYY.YYY\r\nServer address: XX.XXX.XXX.XX\r\nEncryption: 168-bit 3-DES\r\nAuthentication: HMAC-MD5\r\nIP Compression: None\r\nNAT passthrough is active on port TCP 443\r\nLocal LAN Access is disabled\r\n\r\n" (spawn_id exp7) match glob pattern "Client address: "? yes

expect: set expect_out(0,string) "Client address: "

expect: set expect_out(spawn_id) "exp7"

expect: set expect_out(buffer) "rmation.\r\nClient address: "



expect: does "YY.YYY.YYY.YYY\r\nServer address: XX.XXX.XXX.XX\r\nEncryption: 168-bit 3-DES\r\nAuthentication: HMAC-MD5\r\nIP Compression: None\r\nNAT passthrough is active on port TCP 443\r\nLocal LAN Access is disabled\r\n\r\n" (spawn_id exp7) match glob pattern "\r"? yes

expect: set expect_out(0,string) "\r"

expect: set expect_out(spawn_id) "exp7"

expect: set expect_out(buffer) "YY.YYY.YYY.YYY\r"

write() failed to write anything - will sleep(1) and retry...
write() failed to write anything - will sleep(1) and retry...
However - the script doesn't fork to the background, which I'd like it to do to free up my terminal. So, I simply uncomment these two lines:

Code:
# if {[fork]} exit
# disconnect
Now, when I run the script, it fails. It appears that for some reason expect isn't communicating with the forked process at all.

Here's the output from the run with the fork enabled:

Code:
fork: returns {0}

fork: returns {0}

fork: returns {0}

fork: returns {0}

fork: returns {0}

fork: returns {0}

fork: returns {0}

fork: returns {0}

fork: returns {0}

fork: returns {28574}

parent: waiting for sync byte

parent: telling child to go ahead

parent: now unsynchronized from child

spawn: returns {28575}



expect: does "" (spawn_id exp7) match glob pattern "Enter Username and Password."? no

expect: timed out



expect: does "" (spawn_id exp7) match glob pattern "Username"? no

expect: timed out

send: sending "mallarj\r" to { exp7 }



expect: does "" (spawn_id exp7) match glob pattern "Password"? no

expect: timed out

send: sending "PASSWORD\r" to { exp7 }



expect: does "" (spawn_id exp7) match glob pattern "Do you wish to continue?"? no

expect: timed out

send: sending "y\r" to { exp7 }



expect: does "" (spawn_id exp7) match glob pattern "VPN tunnel info"? no

expect: timed out



expect: does "" (spawn_id exp7) match glob pattern "Client address: "? no

expect: timed out



expect: does "" (spawn_id exp7) match glob pattern "\r"? no

expect: timed out

can't read "expect_out(buffer)": no such variable
    while executing
"set myip "$expect_out(buffer)""
    (file "/share/bin/ctl-vpn" line 31)

write() failed to write anything - will sleep(1) and retry...
Any idea what's up?
 
Old 05-06-2007, 11:28 AM   #2
mallarj
LQ Newbie
 
Registered: Oct 2003
Posts: 6

Original Poster
Rep: Reputation: 0
Still stuck on this - anyone have a clue or even suggestions on how to debug?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect Script coolest Programming 7 02-16-2009 03:59 PM
Script... variables with expect? Manana Linux - Networking 1 01-19-2007 04:41 AM
Keyboard no longer working in X Server after monitor reconfigured in YaST Peronthious Linux - General 5 08-25-2006 03:29 AM
telnet server not reliable for expect script powah Linux - Software 0 11-16-2005 11:07 AM
Automae telnet log in and execute commands (expect and send) rajatgarg Linux - Networking 0 06-24-2004 11:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration