The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 10-24-2006
cmf00186 cmf00186 is offline
Registered User
 

Join Date: Oct 2006
Posts: 2
Hep with script to monitor directory

Hello,

I am a newbie who is attempting to write a script to monitor a directory for a set of 3 files that I am expecting to get ftp’d. Occasionally, we suspend operations for maintenance etc. but we still get the files so there can be more than 1 set. If there is more than 1 set, I would like to move all but the latest set to an archive directory.

For example say the files are named:
acme1_090106.txt
acme1_091006.txt
acme1_092206.txt
acme2_090106.txt
acme2_091006.txt
acme2_092206.txt
acme3_090106.txt
acme3_091006.txt
acme3_092206.txt

I would like to move the older files to an archive directory
acme1_090106.txt
acme1_091006.txt
acme2_090106.txt
acme2_091006.txt
acme3_090106.txt
acme3_091006.txt

I am running AIX version 5.31.

This is what I have so far. Any suggestions would be deeply appreciated.

#!/bin/ksh
#
files=0
LoopCnt=0
while (( $files < 4 )); do
echo `date`
for name in `ls acme*`; do
if [ -f $name ]
then let files=files+1
fi
done
if (( $files < 3 )); then
if ((LoopCnt < 6)); then
echo "do not have 3 files yet, sleeping 10 minutes"
echo ""
sleep 600
files=0
let LoopCnt=LoopCnt+1
else
exit
fi
fi
done
This is where I'm stuck

if (( $files > 3)); then
echo "Have more than 3 files, move all but the latest to archive”
exit
fi
Reply With Quote
Forum Sponsor