grep filter the directory
时间:2008-05-19 来源:jordanfang
#!/bin/sh
echo "下面为那些没有在联系人组里面的人" >/opt/tmp/check_person_notingroup.out
file="contacts.cfg contacts_level2.cfg contacts_level3.cfg contacts_level4.cfg contacts_level5.cfg contacts_level6.cfg"
for h in $file
do
for i in `find /usr/local/nagios/svn/objects -type f -name $h |xargs -i cat {} | grep contact_name | awk '{print $2}'`
do
grep $i /usr/local/nagios/svn/objects/contactgroups.cfg 2>/dev/null 1>/dev/null || grep $i /usr/local/nagios/svn/objects/contactgroups_charge.cfg 2>/dev/null 1>/dev/null
if [ $? -ne 0 ]
then
echo $i >>/opt/tmp/check_person_notingroup.out
fi
done
done
echo "下面的联系人组是没在使用中的" >>/opt/tmp/check_person_notingroup.out
cd /usr/local/nagios/svn/
dir=`ls -l | grep -v total | grep -v objects |awk '{print $9}'`
for group in `cat /usr/local/nagios/svn/objects/contactgroups.cfg | grep contactgroup_name | awk '{print $2}'`
do
grep -r $group $dir 2>/dev/null 1>/dev/null
if [ $? -ne 0 ]
then
echo $group >>/opt/tmp/check_person_notingroup.out
fi
done
cat /opt/tmp/check_person_notingroup.out
把没在线上的联系人和联系组,删除
下面一段主要为了过滤objects文件夹才做的一个土办法,办法土点但是还是有效的
echo "下面为那些没有在联系人组里面的人" >/opt/tmp/check_person_notingroup.out
file="contacts.cfg contacts_level2.cfg contacts_level3.cfg contacts_level4.cfg contacts_level5.cfg contacts_level6.cfg"
for h in $file
do
for i in `find /usr/local/nagios/svn/objects -type f -name $h |xargs -i cat {} | grep contact_name | awk '{print $2}'`
do
grep $i /usr/local/nagios/svn/objects/contactgroups.cfg 2>/dev/null 1>/dev/null || grep $i /usr/local/nagios/svn/objects/contactgroups_charge.cfg 2>/dev/null 1>/dev/null
if [ $? -ne 0 ]
then
echo $i >>/opt/tmp/check_person_notingroup.out
fi
done
done
echo "下面的联系人组是没在使用中的" >>/opt/tmp/check_person_notingroup.out
cd /usr/local/nagios/svn/
dir=`ls -l | grep -v total | grep -v objects |awk '{print $9}'`
for group in `cat /usr/local/nagios/svn/objects/contactgroups.cfg | grep contactgroup_name | awk '{print $2}'`
do
grep -r $group $dir 2>/dev/null 1>/dev/null
if [ $? -ne 0 ]
then
echo $group >>/opt/tmp/check_person_notingroup.out
fi
done
cat /opt/tmp/check_person_notingroup.out
把没在线上的联系人和联系组,删除
下面一段主要为了过滤objects文件夹才做的一个土办法,办法土点但是还是有效的
相关阅读 更多 +