find files older than 30mins,count and send mail

Hi all,

I wrote this script to find files older than time parameter, count the number of files, and send an email to me that some files are in a particular folder. For the particular path, the script should wait delay parameter before running again.

For example, assuming the input file looks like this

20 A/B/ 5m
10 C/D 4m

The script changes dir to A/B, finds all files older than 20mins,counts them and sends an email to me.It then waits 5minutes before running again.It, however,keeps running to process the second path (C/D). It only waits if it found files older than the time parameter, otherwise it does nothing.It waits only for the path if found files, otherwise it keeps processing other paths.

I wrote something like this but doesnt seem to work

#!/bin/ksh
#The filepathinput format is 30 /A/B/C/gunner 10m
while read AGE PATH DELAY
do
  cd $PATH
  for file in $(ls)
  
      do [[ $(( $(./fileage $file)/60)) -ge $AGE ]]     
       echo $file >>outputfiles.txt
      done
    
    final=`wc -l outputfiles.txt|awk '{print $1}'`
    if $final -ge 1
    then
    echo $final|mailx -s "Unprocessed Files in blabla" gunner.love@henry.com    
    else
      echo "Everything's OK"
    fi
    rm -f outputfiles.txt
    sleep $DELAY
    
  cd -
done < filepathinput.txt

Please advise.

Thank you

Replace the code :

  for file in $(ls)
  
      do [[ $(( $(./fileage $file)/60)) -ge $AGE ]]     
       echo $file >>outputfiles.txt
      done

with

  for file in $(ls)
  do
     if  [[ $(( $(./fileage $file)/60)) -ge $AGE ]]
     then     
        echo $file >>outputfiles.txt
     fi
  done >outputfiles.txt

and replace

    if $final -ge 1

with

    if [ $final -ge 1 ]

Jean-Pierre.

Hi,
I ran the scriipt but got these errors. I checked the ksh path and its in bin/ksh and usr/bin/ksh.

 sh -x trymonitor.sh
+ 0< filepathinput.txt
+ read AGE PATH DELAY
+ cd /A/B/C/
+ 1> outputfiles.txt
+ ls
trymonitor.sh[12]: ls:  not found.
+ + awk {print $1}
+ wc -l outputfiles.txt
trymonitor.sh[14]: awk:  not found.
trymonitor.sh[14]: wc:  not found.
final=
+ [ -ge 1]
trymonitor.sh[15]: test: A ] character is missing.
+ echo Everything's OK
Everything's OK
+ rm -f outputfiles.txt
trymonitor.sh[21]: rm:  not found.
+ sleep 10m
trymonitor.sh[22]: sleep:  not found.
+ cd -

The path for commands (ls, awk, ...) is not set.
Verify the environment variable PATH.

If your script run fron cron, don't forget that the environment is not set (.profile is not executed).

Jean-Pierre.

why dont you try find command by which you could do it in one command only