Last active
January 18, 2018 22:41
-
-
Save edvasqueza/dd2514ef184038e23047 to your computer and use it in GitHub Desktop.
expect script for activate checkpoint vpn without writing your password every time. You need to install the snx tool for using it. The sh file is optional, used to keep trying to connect if your first try fails. sudo ln -s /full/path/to/your/file /usr/local/bin/name_of_new_command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/expect | |
| set timeout 10 | |
| log_user 0 | |
| send_user "desconectando si es que hay alguna sesion abierta\n" | |
| spawn snx -d | |
| expect { | |
| timeout { exit 2 } | |
| eof { | |
| sleep 1 | |
| send_user "intentando conectar a vpn...\n" | |
| spawn -ignore HUP /bin/sh -c "snx" | |
| expect { | |
| "password:" { | |
| send "<<PASSWORD>>\r" | |
| expect { | |
| "connected." { | |
| send_user "conectado!\n" | |
| exit 0 | |
| } | |
| "Connection aborted." { | |
| send_user "conexion abortada\n" | |
| exit 1 | |
| } | |
| eof { | |
| send_user "hubo un error\n" | |
| exit 1 | |
| } | |
| timeout { | |
| send_user "timeout\n" | |
| exit 2 | |
| } | |
| } | |
| } | |
| eof { | |
| send_user "hubo un error\n" | |
| exit 1 | |
| } | |
| timeout { | |
| send_user "timeout\n" | |
| exit 2 | |
| } | |
| } | |
| } | |
| } | |
| expect eof | |
| exit 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| deft=3 | |
| rc=1 | |
| t=${1:-$deft} | |
| n=1; | |
| ec=0 | |
| while [ $rc -ne 0 ] && [ $n -le $t ] | |
| do | |
| echo "*** intento $n ***" | |
| expect ~/vpn.expect | |
| rc=$? | |
| ec=$rc | |
| n=$((n+1)) | |
| done | |
| exit $ec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment