#!/bin/bash
grep_result="/tmp/grep.txt"
result_file="/tmp/result.txt"
ftp_path=$(find /twas-nds/ftp_root/result-data/flow-files/ -type d|tail -n 1)
result_json="/tmp/result"
set -x
check_status(){
ps -ef|grep $0|grep -v $$|grep -v grep&&exit
}
delete_tmp_file(){
[ -d $result_json ]||mkdir -p $result_json
[ -f $grep_result ]&&rm -rf $grep_result
[ -f $result_file ]&&rm -rf $result_file
}
search_data(){
thread_num=400
tempfifo="my_temp_fifo"
mkfifo ${tempfifo}
exec 6<>${tempfifo}
rm -f ${tempfifo}
for ((i=1;i<=${thread_num};i++))
do
{
echo;
}
done >&6
for file in $(find $ftp_path -type f|grep json);do
read -u6
{
touch ${result_json}/${file##*/}
for json in $file;do
grep -oE '((([0-9]+)\.){3}([0-9]+))' $json|grep -v $HOSTNAME|sort|uniq >>${result_json}/${file##*/}
done
echo " ">&6
}&
done
wait
exec 6>&-
}
total_data(){
cd $result_json
ls|grep json|xargs -i -t cat {}|awk '!a[$0]++' >>$grep_result
}
result_data(){
grep -oE '((([0-9]+)\.){3}([0-9]+))' $grep_result|sort -t"." -k1,1n -k2,2n -k3,3n -k4,4n|uniq >>${result_file}
[ -f $grep_result ]&&rm -rf $grep_result
[ -d $result_json ]&&rm -rf $result_json
}
Main(){
check_status
delete_tmp_file
search_data
total_data
result_data
}
Main