I am trying to retrieve the files generated in the specific directory using ‘Find’ and trying to retrieve files generated last 2 days. The script is consuming so much time to execute. My directory has Hindered thousands of files generated from last few years. My requirement is to fetch only files generated from last 2 days. Post fetching the file names I am trying to find Unique pattern and trying to count each unique pattern. Would request you to advise how better I could optimize the script.
script:
<Condition>
then
find /path/ type f -name ‘pattern*.pdf’ -newermt ‘yesterday 0:00’|awk -F "/" ‘{print $NF}’>>/path/filesonday.txt
find /path/ -type f -name ‘pattern*.pdf’ -exec ls --fu {} ;| grep "$(date +"%Y-%m-%d")">>/ path /files.txt
find / path -type f -name ‘pattern *.pdf’ -newermt ‘yesterday 0:00’|awk -F "/" ‘{print $NF}’>>/ path /filesonday.txt
find /path/ -type f -name ‘pattern*.pdf’ -exec ls --fu {} ;| grep "$(date +"%Y-%m-%d")">>/ path /files.txt
val1=0
while read line
do
value=echo $line
val1=$(( ${#value} | cut -c1-15));
echo $value|cut -c -$val1 >>/path/filepatternsoncurrentday.txt
done < /path/filesonday.txt
sort filepatternsoncurrentday.txt|uniq>>/path/finaluniquepatterns.txt
temp=""
val1=0
value=""
while read line
do
value=echo $line
if [[ $temp != $value || $temp = "" ]]
then
val1=find /path/ -type f -name "$value*" -newermt 'yesterday 0:00'|wc -l
echo " $value|$val1" >> /path/patterncount.txt
temp=echo $value
fi
done < /path/finaluniquepatterns.txt
batchdate=echo $value|awk -F "_" '{print $NF}'
echo " $batch $batchdate">>batchdetails.txt
sh /tmp/Pmail.sh
else
echo "Failed"
fi