我想通过uci配置ipsec (总是ipsec)。如果存在ipsec部分,则一切正常工作。我可以使用uci ipsec .@ipsec.type=‘can’修改ipsec。但是,如果ipsec部分不存在,则此命令不起作用。如果不存在,我想添加ipsec部分。
发布于 2019-08-10 16:16:36
我找到的唯一方法是使用shell脚本
if ! uci -q show ipsec.@ipsec[0]
then
uci add ipsec ipsec
fi
发布于 2019-11-14 16:52:23
uci show ipsec
将显示配置,而不是ipsec,因此条件将变得错误,您将以添加多个ipsec ipsec1配置结束,您可以通过以下方式完成此操作。
config ipsec
option type 'tunnel'
type_present=`uci -q get ipsec.@ipsec[0]`
if [ "$type_present" = ""]; then
uci add ipsec ipsec
uci commit ipsec
fi
如果您只有一个配置ipsec,则可以将配置部分命名为
config ipsec 'my_ipsec' # my_ipsec is named config
你可以通过更好的方式访问它
uci get ipsec.my_ipsec.type
使用-q -> quite模式,如果未找到条目,该模式将不会通过错误并返回空字符串。
https://stackoverflow.com/questions/57439809
复制相似问题