Hi
If there is a file upload done from a remote server
and if the file remains without being extracted for more than an hour,
I need to identify the files and create an alert message to the
users in the other end.
please help me writing a shell script for it.
You'll need to come up with your own way of determining if it's been extracted or not (or provide more details as to what changes in the file or filename).
I can help with some pseudo code for the rest though:
period=300 # 5 mins
threshold=3600 # 1 hour
now=`date +%Y%m%d%H%M%S`
while true
do
for file in <your test for the presence of unprocessed files>
do
difference=$now - `<get $file mtime>`
if [ $difference -ge $threshold ]
then
<raise an alarm for $file being $difference old>
fi
done
done
If you have perl, this script will find all files not modified in the last hour...
#!/usr/bin/ksh
function file_hours {
perl -e 'printf "%i\n", 24*(-M shift);' -- $1
}
cd wherever
for file in *
do
if [[ $(file_hours $file) -ge 1 ]]
then
echo $file is old
else
echo $file is new
fi
done