Reputation: 4888
I need to write a shell script that help me to automatically connect to vpn after executing this script
A vpnc program require following inputs
root@xmpp3:/home/test/Desktop/ScriptTovpnc# vpnc
Enter IPSec gateway address:
Enter IPSec ID for :
Enter IPSec secret for @:
Enter username for :
Enter password for @:
vpnc: unknown host `'
I am unable to write script,how i will pass all these parameters in that script.
Upvotes: 0
Views: 283
Reputation: 10653
anishsane's comment is right. Use a config file!
But just in case here is expect
script that automates the entering of your data:
#!/usr/bin/expect
spawn vpnc
expect "Enter IPSec gateway address;"
send "yourdata\r";
expect "Enter IPSec ID for"
send "yourdata\r";
expect "Enter IPSec secret for"
send "yourdata\r";
expect "Enter username for"
send "yourdata\r";
expect "Enter password for"
send "yourdata\r";
And you can make it smaller if you pass most of your data as command line arguments as suggested by Jonathan:
#!/usr/bin/expect
spawn vpnc --gateway yourgateway --id yourid --username yourusername
expect "Enter IPSec secret for"
send "yourdata\r";
expect "Enter password for"
send "yourdata\r";
But as already mentioned, it is not the way to go. Use a config file instead.
Upvotes: 2