I have a sample code in which a grep is being performed from multiple files with a date format in their naming convention. Here the script:
#! /usr/bin/bash
cd /IN/service_packages/SMS/cdr/received
MYDATE=`date +"%Y%m%d%H%M"`
#get the value then divide by 60
#DAPS_SLC01
data=`grep "CALL TYPE=D" cubic-live-slc-a_ACS_$MYDATE* | wc -l`
echo Data:
r=`echo "scale=3; $data/60" | bc | sed -e 's/^\./0./;s/[0]*$//g'`
echo DAPS_SLC-a $r
#DAPS_SLC02
data1=`grep "CALL TYPE=D" cubic-live-slc-b_ACS_$MYDATE* | wc -l`
r=`echo "scale=3; $data1/60" | bc | sed -e 's/^\./0./;s/[0]*$//g'`
echo DAPS_SLC-b $r
#DAPS Total
r=`echo "scale=3; ($data + $data1)/60" | bc | sed -e 's/^\./0./;s/[0]*$//g'`
echo DAPS_Total $r
Sometimes when the script is run, the files with that timestamp are not created yet, so of course the grep will fail. How can I input a sleep to wait till the files exist, then run the grep?
Thanks elbrand. I used the min/maxdepth but the command did not work on my version (Solaris 11).
I then used Scrutinizer's until and it worked perfectly.
Many thanks to both for your input.