Friday, January 8, 2010

Shell script for file checking

I recently found I needed a simple way to determine if the correct number of daily files had been received and processed on my BPEL server. Since the server NFS mounts to a Windows share that has files being FTP'd to, there were a lot of places where a file might not make it. The shell script below checks for the number of instances of a file that has the date stamp in the file name and emails the count to me. This is set up on a daily (week days) cron.

#!/bin/bash

subject="Daily File Status"
email="name@domain.com"
eml_message=""

run_date=`date "+%Y%m%d"`
m1="*_"
m2="_*"
file_mask="$m1$run_date$m2"

count=0

#echo $file_mask

cd /BPEL/archive

for file in `ls -1 $file_mask`
do
# echo "Found file"
count=`expr $count + 1`
done

eml_message=`echo "Number of files found on the BPEL server for today was ( $count ). Normally this count should be (2)"`

echo $eml_message | /bin/mail -s "$subject" "$email"

A better solution is to check for the number of invoked instances...I'll be posting that next.