有一个脚本,处理一个一个服务器中无用的folders。其中用到了comm,comm是比较两个文件的异同,但是要求这两个文件的内容必须是被sort的。
这里ls把当前所有的目录都记录到/home/nova/nan/validation/tmp里,注意,这个tmp是需要与其他文件比较的,看似 ls > /home/nova/nan/validation/tmp 并没有在保存之前sort内容,
但是ls命令本身就有sort的功能,罗列的文件是被sort之后的,所以这里不再需要sort命令!
例如如下,
-
#!/bin/env bash
-
# the delete the invalid folders in integration which do not exit in production.
-
# note: the script locates in /home/nova/scripts/graphite/ (created by nova account)
-
# but run by graphite account.
-
# full path is needed for this job.
-
-
echo '' > /home/xxxx/nan/validation/production_list
-
-
# list all valid folders to production_list
-
cd /opt/xxxx/storage/xxxxx/Opsview/GOP-xxxxxx/
-
-
find . -mindepth 3 -maxdepth 3 -type d | grep -ve \.\/int | cut -d\/ -f4 | \
-
sort | uniq > /home/nova/nan/validation/production_list
-
-
# delete invalid folders
-
lines=$(wc -l /home/xxxx/nan/validation/production_list | egrep -io [0-9]+)
-
if [ "$lines" -gt 2000 ];then
-
for i in /opt/xxxx/storage/xxxxx/Opsview/GOP-xxxxxx/int*;
-
do
-
cd $i/RPM5
-
ls > /home/xxxx/nan/validation/tmp
-
for a in $(comm -23 /home/xxxx/nan/validation/tmp /home/nova/nan/validation/production_list)
-
do
-
#rm -rf $a
-
ls -ld $a
-
done
-
done
-
else
-
echo "$(date +%Y-%m-%d-%H-%M):error in /home/xxxx/nan/validation/production_list"
-
>> /home/xxxx/nan/validation/dellog
-
fi
阅读(1796) | 评论(0) | 转发(0) |