Avatar of hypervisor

asked on 

Need a script to re-initiate a OpenSwan VPN tunnel when it fails

I need to initiate the following commands if a ping fails to an IP address.

sudo ipsec whack --name sonicwall --delete
sudo ipsec auto --add sonicwall
sudo ipsec whack --name sonicwall --initiate

Open in new window

The last command prompts for a username and password (as displayed below.)  The script will need to provide the username and password.
[ec2-user@ip-10-170-95-135 ~]$ sudo ipsec whack --name sonicwall --initiate
002 "sonicwall" #41: initiating Aggressive Mode #41, connection "sonicwall"
112 "sonicwall" #41: STATE_AGGR_I1: initiate
003 "sonicwall" #41: ignoring Vendor ID payload [Sonicwall 1 (TZ 170 Standard?)]
003 "sonicwall" #41: ignoring unknown Vendor ID payload [5b362bc820f60007]
003 "sonicwall" #41: received Vendor ID payload [Dead Peer Detection]
003 "sonicwall" #41: received Vendor ID payload [XAUTH]
002 "sonicwall" #41: Aggressive mode peer ID is ID_FQDN: '@0017C5120524'
002 "sonicwall" #41: transition from state STATE_AGGR_I1 to state STATE_AGGR_I2
004 "sonicwall" #41: STATE_AGGR_I2: sent AI2, ISAKMP SA established {auth=OAKLEY_PRESHARED_KEY cipher=oakley_3des_cbc_192 prf=oakley_sha group=modp1024}
041 "sonicwall" #41: sonicwall prompt for Username:
Enter username:   amazoncloudCA
040 "sonicwall" #41: sonicwall prompt for Password:
Enter passphrase: 

Open in new window

I don't particularly care what scripting tools are used to get this done.

Shell Scripting

Avatar of undefined
Last Comment

8/22/2022 - Mon