为简单起见进行编辑。
添加现有变量:
time=`date +'%d%m%y_%H%M'`
temp_file=temp\_$input_file.txt
final=$time\_Parsed_CSV.config
原始 CSV ($temp_file) - 实际名称不是“主机/组”任何东西 - 需要根据 $2 进行过滤
host_a,host,192.168.0.1
host_b,host,192.168.0.2
host_c,host,192.168.0.3
group_a,group,host_a
group_a,group,host_b
group_b,group,group_a
group_b,group,host_c
需要一个 AWK 字符串来解析 $2 'group' 对象,如下所示:
当 $2 = 'group' AND $3 = 在其他地方也被定义为组的对象(例如 group_a)时,命令需要是:
awk -F "[,|]" '{if ($2=="group") print "set security address-book global address-set",$1,"address-set",$3}' $temp_file >> $final
否则 - 假设它是一个普通主机,并打印:
awk -F "[,|]" '{if ($2=="group") print "set security address-book global address-set",$1,"address",$3}' $temp_file >> $final
我希望输出看起来像: 对于嵌套组(group_b 中的 group_A):
set security address-book global address-set group_b address-set group_a
对于组中的普通主机(group_a 中的 host_a)
set security address-book global address-set group_a address host_a