Saturday, August 7, 2021

search utility

     #/bin/ksh

rm -rf stored_files sorted_search_files 2>/dev/null

while read file_list

do

    echo "======================================================================================" >> stored_files

    echo "Search Directory : $file_list" >> stored_files

echo "**************************************************************************************" >> stored_files

while read search_line

do

    find "$file_list"  -maxdepth 1 -name "*" ! -name "*.dat*" ! -name "*.bad*" ! -name "*.pdf*" ! -name  "*.txt*" ! -name  "*.log*" ! -name "*.csv*" -type f -exec egrep -i "$search_line" {} \; -print >> stored_files

    find "$file_list"  -maxdepth 1 -name "*" ! -name "*.dat*" ! -name "*.bad*" ! -name "*.pdf*" ! -name  "*.txt*" ! -name  "*.log*" ! -name "*.csv*" -type f -exec egrep -il "$search_line" {} \; -print >> sorted_search_files

done < search_list

echo "======================================================================================" >> stored_files

done < search_directory

if [ -f "sorted_search_files" ] ; then

    sort -u sorted_search_files |mailx -s "Searched File List" emailAddress

    echo "Check your email"

fi

if [ -f "stored_files" ] ; then

    echo "Searched file content is created in the directory `pwd` file name : stored_files" 

    uuencode stored_files stored_files |mailx -s "Searched File List Content" emailAddress

fi

No comments:

Post a Comment