find files older than 30mins,count and send mail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find files older than 30mins,count and send mail
# 1  
Old 09-27-2006
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  
Old 09-27-2006
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  
Old 09-27-2006
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  
Old 09-27-2006
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  
Old 09-27-2006
why dont you try find command by which you could do it in one command only
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to send mail using find command?

Hello, I wanted to send mail to multiple receiptant by using uuencode with find command. I have used the below find command to search a file, which generating daily at the particular time. . find . -type f -mtime -1 -printf '%f %TH:%TM\n' | awk '$NF>"06:40" && $NF<"06:50" {print $1}' I... (2 Replies)
Discussion started by: pokhraj_d
2 Replies

2. Shell Programming and Scripting

Sftp - 1 day older files count

Need to write a shell script on AIX box which will connect to different servers using SFTP and get the file count of only 1 day older files. (purging list) How to achieve this? On local server we can use: find <path> -type f -mtime +1 But how to do it in case of SFTP? Please advise. Thanks... (9 Replies)
Discussion started by: vegasluxor
9 Replies

3. UNIX for Advanced & Expert Users

Zip the files if count is more than 0 and send a mail

All, I am new to shell scripting and trying to get the count of files that starts with error and with extension .out, if the count is greater than 0 and zip the file and send an email with the content of error.out file, here is my script cd /temp testcount =$('find . -name '*.out' -print |... (4 Replies)
Discussion started by: luckydoll
4 Replies

4. Shell Programming and Scripting

Command to Count the files which is Older than 3 months?

Hi Gurus the count of files in a particular Directory... ls -lrth | grep -c ^- can any one share the command to Count the files which is Older than 3 months So please help me out in this Thanks in Advance (2 Replies)
Discussion started by: SeenuGuddu
2 Replies

5. UNIX for Advanced & Expert Users

find files older than 30 days old

Hello, I have a script which finds files in a directory that are older than 30 days and remove them. The problem is that these files are too many and when i run this command: find * -mtime +30 | xargs rm I run this command inside the directory and it returns the error: /usr/bin/find:... (8 Replies)
Discussion started by: omonoiatis9
8 Replies

6. Shell Programming and Scripting

find files older than and containing then tar.

I'm tring to: find files recursively older than x days that contain dat or DAT then tar them I can find the files older than 90 days containing dat with this: find . -mtime +90 -type f -name "*dat*" -exec tar -cvvfp /some/path/some.tar {} \; but how do I do it case insensitive? ... (3 Replies)
Discussion started by: Ikon
3 Replies

7. UNIX Desktop Questions & Answers

Find files older than 10 days

What command arguments I can use in unix to list files older than 10 days in my current directory, but I don't want to list the hidden files. find . -type f -mtime +15 -print will work but, it is listing all the hidden files., which I don't want. (4 Replies)
Discussion started by: Pouchie1
4 Replies

8. Shell Programming and Scripting

How to find files older than 30 days

Dear Friends, I have two queries. 1) I want to see the list of folders which were created 29 days ago. 2) I want to see the folders in which last created file is older than 29 days. Can it be done? Thank you in advance Anushree (4 Replies)
Discussion started by: anushree.a
4 Replies

9. Shell Programming and Scripting

script to find a file and send a mail

I need a shell script which checks for a file in a particuler folder and should send me a mail if the file of that name is present. Please help me on this.I am new to shell scripting. (6 Replies)
Discussion started by: jayaramanit
6 Replies

10. Shell Programming and Scripting

Find files older than 20 days & not use find

I need to find files that have the ending of .out and that are older than 20 days. However, I cannot use find as I do not want to search in the directories that are underneath the directory that I am searching in. How can this be done?? Find returns files that I do not want. (2 Replies)
Discussion started by: halo98
2 Replies
Login or Register to Ask a Question