I've got script in crontab which creates every 30 minutes files with list of Offline peers in asterisk:
我在crontab中有脚本,每隔30分钟创建一个带有星号中脱机对等列表的文件:
now=$(date +"%Y%m%d%H%M")
/usr/sbin/asterisk -rx 'sip show peers' | grep "Unspec" | sed 's/[/].*//' >> /var/log/asterisk/offline/offline_$now
I need to parse theese files and find extensions that were always offline, i.e. stings in files that were constant.
我需要解析theese文件并找到始终处于脱机状态的扩展名,即在不变的文件中查找。
How can I do this?
我怎样才能做到这一点?
Output is:
/usr/sbin/asterisk -rx 'sip show peers' | grep "Unspec" | sed 's/[/].*//' | tail -3
891
894
899
ls /var/log/asterisk/offline/
offline_201309051400 offline_201309051418 offline_201309051530 offline_201309051700
offline_201309051830 offline_201309052000 offline_201309052130
offline_201309051405 offline_201309051430 offline_201309051600 offline_201309051730
offline_201309051900 offline_201309052030 offline_201309052200
offline_201309051406 offline_201309051500 offline_201309051630 offline_201309051800
offline_201309051930 offline_201309052100 offline_201309052230
1 个解决方案
#1
0
This awk script will print the lines that are present in all of the files:
这个awk脚本将打印所有文件中的行:
awk 'FNR==1{f++}{a[$0]++}END{for (i in a) if (a[i]==f) print i}' offline_*
How it works:
这个怎么运作:
- With
FNR==1{f++}
we count the number of files that are parsed (FNR is equal to one for the first line of each file) - with
{a[$0]++}
we count how many times each line has appeared. - the
END
block prints the elements of the array that have been found f times.
使用FNR == 1 {f ++},我们计算解析的文件数(FNR等于每个文件的第一行一个)
用{a [$ 0] ++}我们计算每行出现的次数。
END块打印已找到f次的数组元素。
#1
0
This awk script will print the lines that are present in all of the files:
这个awk脚本将打印所有文件中的行:
awk 'FNR==1{f++}{a[$0]++}END{for (i in a) if (a[i]==f) print i}' offline_*
How it works:
这个怎么运作:
- With
FNR==1{f++}
we count the number of files that are parsed (FNR is equal to one for the first line of each file) - with
{a[$0]++}
we count how many times each line has appeared. - the
END
block prints the elements of the array that have been found f times.
使用FNR == 1 {f ++},我们计算解析的文件数(FNR等于每个文件的第一行一个)
用{a [$ 0] ++}我们计算每行出现的次数。
END块打印已找到f次的数组元素。