3

Below is an shell script I have written to automate entering the password for the vpnc command. The expect works fine and vpnc activated automatically after password entered, but I need to get the exit status of the vpnc command. How can I get the exit status of vpnc?

VPNC=/bin/vpnc

expect_ACTIVATE=`cat << EOF
set timeout -1
spawn  $VPNC 
expect    :            {send Pass123\r}
expect eof
EOF`

expect -c  "$expect_ACTIVATE"

I've tried doing the following to get the exit status into STATUS, but it's not quite right:

expect_ACTIVATE=`cat << EOF
set timeout -1
spawn  $VPNC 
expect    :            {send Pass123\r}
STATUS=` echo $? `
expect eof
EOF`
1

I am guessing this. I didn't try it myself. Let's see if it works.

expect_ACTIVATE=`cat << EOF`
set timeout -1
spawn  $VPNC 
expect    :            {send Pass123\r}
expect "\\$ "
send "status=`echo $?\r`"
expect eof
EOF

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.