On recent Linux systems you need to use systemd.
Create file /etc/systemd/system/my_vpn.service
with following contents:
[Unit]
Description=Connect to my VPN
After=network.target
[Service]
Type=simple
Environment=password=correcthorsebatterystaple
ExecStart=/bin/sh -c 'echo $password | sudo openconnect -u username --passwd-on-stdin vpn.server.tld'
Restart=always
[Install]
WantedBy=multi-user.target
Then execute:
sudo systemctl daemon-reload
sudo systemctl enable my_vpn
sudo systemctl start my_vpn
You’re done!