2

I am trying to automate the establishment of a VPN connection that uses snx.

Was hoping someone could help figure out why in the below expect script, the spawned snx process just dies expect reaches 'expect eof'. If I run the below script and watch ps -auxef, I can see that the snx connection gets established, but then dies as soon as that line is reached.

#!/usr/bin/expect

log_user 0
send_user "attempting to establish vpn connection..."
spawn snx -s server.com -p 443 -u myuser
expect {
        "Please enter your password:\n" {
                send "password123\r"
                expect eof
                send_user "successful\n"
                exit 0
        }
        eof {
                send_user "vpn is already connected\n"
                exit 0
        }
}

The weird thing is that if I run the snx command manually and enter the password, it runs fine.

Another weird thing is this issue is only seen when I run it from an ssh session into a Fedora 17 box, however when I run on my local machine (Fedora 18), it runs 100% fine. Any ideas? Any help is appreciated!

SS781
  • 2,507
  • 2
  • 14
  • 17
  • 1
    So, after hours of trying to debug this, I settled for a workaround of a heredoc to send the password in. Surprisingly it works just fine. I am still curious about the answer to the original question though. – SS781 Jan 11 '14 at 22:05

1 Answers1

2

Please do like

spawn -ignore HUP /bin/sh -c "snx -s xxx.xxx.xxx.xxx -u vpn_account"

This will prevent the termination

Narendra
  • 3,069
  • 7
  • 30
  • 51
gan yew
  • 21
  • 2