0

我需要编写一个 shell 脚本来帮助我在执行此脚本后自动连接到 vpn

vpnc 程序需要以下输入

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 `'

我无法编写脚本,我将如何在该脚本中传递所有这些参数。

4

1 回答 1

2

anishsane 的评论是正确的。使用配置文件!

但以防万一这里是expect自动输入数据的脚本:

#!/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";

如果您按照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";

但正如已经提到的,这不是要走的路。请改用配置文件。

于 2013-09-06T09:55:24.590 回答