The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to find files older than 2 hours pt14 AIX 3 03-05-2008 08:31 AM
how to find files older than 4hours in HP-UX caprikar UNIX for Advanced & Expert Users 3 11-27-2007 01:23 PM
find files older than a given file Shivdatta Shell Programming and Scripting 5 07-24-2006 04:25 AM
only find files older than x minutes old dsimpg1 Shell Programming and Scripting 1 05-18-2006 08:48 PM
Find files older than 20 days & not use find halo98 Shell Programming and Scripting 2 05-18-2006 11:19 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-27-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
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

Code:
#!/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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-27-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,158
Replace the code :
Code:
  for file in $(ls)
  
      do [[ $(( $(./fileage $file)/60)) -ge $AGE ]]     
       echo $file >>outputfiles.txt
      done
with
Code:
  for file in $(ls)
  do
     if  [[ $(( $(./fileage $file)/60)) -ge $AGE ]]
     then     
        echo $file >>outputfiles.txt
     fi
  done >outputfiles.txt
and replace
Code:
    if $final -ge 1
with
Code:
    if [ $final -ge 1 ]


Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 09-27-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
followup

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

Code:
 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 -
Reply With Quote
  #4 (permalink)  
Old 09-27-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,158
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.
Reply With Quote
  #5 (permalink)  
Old 09-27-2006
Registered User
 

Join Date: Sep 2006
Posts: 37
why dont you try find command by which you could do it in one command only
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0