Script to check if files are being sent

SunOS -s 5.10 Generic_147440-04 sun4u sparc SUNW,SPARC-Enterprise

Hi,

on one system there are folders which are being created based on today's date

/data/CDR/sswitch_roa/voice/bkup/<yyyymmdd> (e.g /data/CDR/sswitch_roa/voice/bkup/20180620 � is the path for today�s files)

Files are being spooled in each of the daily folders that are created.

The script should verify for each day when files spooled in those folders are not being received for more than 1 hour - this will be done by checking the current timestamp of the files and if the timestamp of the files exceeds 1 hour, an email will be sent to the user.

Please find attached.

Can anyone please guide me with the script?

  1. I should loop the directory
DATE_DIR=`date +%Y%m%d`;

cd /data/CDR/sswitch_roa/voice/bkup/$DATE_DIR

 

 

ls *.gz > /data/CDR/sswitch_roa/voice/bkup/files

for i in `cat files`

do

<to check i's current date and if the timestamp of the file exceeds more than 1 hour, an email will be sent to the user>
if(DATE_DIR - i's current date)>1
 then email... 

 

done

Thanks,

Joe

Are you checking that all the files have been sent in the last hour, or just the latest file?

Solaris is rather limited in what you can do with respect to date and file timestamps but how about something like this (untested)?

DATE_DIR=$(date +%Y%m%d)
cd /data/CDR/sswitch_roa/voice/bkup/${DATE_DIR}
typeset -Z2 hour
hour=$(( $(date +%H) - 1 ))
if [[ $hour -lt 1 ]]
then exit
fi
tmpfile=$(mktemp)
touch -t $(date +"%m%d$hour%M$S") ${tmpfile}
latest_file=$(ls -t *.gz | head -1)
if /usr/xpg4/bin/test ${latest_file} -nt ${tmpfile}
then
# we have files newer than one hour
else
# nothing in the last hour
fi
rm ${tmpfile}

This requires /bin/ksh to run the code.

I have tested some of the statements standalone on a Solaris system so I am confident you can get something to work from here.

Andrew