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";
但正如已经提到的,这不是要走的路。请改用配置文件。