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 and shell scripting languages 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 12:31 PM
how to find files older than 4hours in HP-UX caprikar UNIX for Advanced & Expert Users 3 11-27-2007 05:23 PM
find files older than a given file Shivdatta Shell Programming and Scripting 5 07-24-2006 08:25 AM
only find files older than x minutes old dsimpg1 Shell Programming and Scripting 1 05-19-2006 12:48 AM
Find files older than 20 days & not use find halo98 Shell Programming and Scripting 2 05-18-2006 03:19 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-27-2006
kayarsenal kayarsenal is offline
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
  #2 (permalink)  
Old 09-27-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,429
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.
  #3 (permalink)  
Old 09-27-2006
kayarsenal kayarsenal is offline
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 -

  #4 (permalink)  
Old 09-27-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,429
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.
  #5 (permalink)  
Old 09-27-2006
hitmansilentass hitmansilentass is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 37
why dont you try find command by which you could do it in one command only
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0