Monitor file generation for an hour using Korn shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Monitor file generation for an hour using Korn shell script
# 1  
Old 05-06-2010
Monitor file generation for an hour using Korn shell script

Hi,

I am new to this unix scripting, I got a requirement like..

Files with *.XML extension will be generating in a /home/sample/ folder for every 15 mins. I need to monitor those files in that particular folder for every hour.
If no file has been generated in that particular folder for an hour, need to send a mail to particular group.

Can anyone please help me??

Thanks in advance..
# 2  
Old 05-06-2010
Great tins brethren...

Kindly post the script, or an extract thereof... so we can see what you've done so far. That way it's easier to post suggestions or pointers...

I will however suggest you familiarise yourself with the 'date' command... that way you can simply do a something like this:

Code:
compare_date=`date | awk '{print $2" "$3" "$4}'`

the output should be something like this:

May 6 11:27:20 (you can use sed to remove ":20"

then do a listing for all *.XML files in that directory:

Code:
file_timestamp=`ls -ltr *.XML| awk '{print $6" "$7" "$8}'`

using the two variables returned... you can use some arithmetic, and do a subtraction, to compare the timestamp of the last file generated, to the current time (you can use an if statement for this).

What OS would you like to do this on?
# 3  
Old 05-06-2010
Monitor file generation for an hour using Korn shell script

Hi ,

I want to write the shell script in UNIX box. Could you please send me the code.

Files with *.XML extension will be generating in a /home/sample/ folder for every 15 mins. I need to monitor those files in that particular folder for every hour.
If no file has been generated in that particular folder for an hour, need to send a mail to particular group.

Can anyone please help me??

Thanks in advance..
# 4  
Old 05-06-2010
Have you tried the code i sent you in the previous post?

I understand you want to write the script on a UNIX box... are you speaking of solaris? if so what version?

Have you started with the script already, or are you just looking for somebody to send you the working code? Since you mentioned you are new to scripting, I don't think it would be advisable to do copy, pastes of code... You need to understand what the commands in your script do, and how they work...

Please type the following command:

Code:
uname -a


Last edited by Scott; 05-06-2010 at 07:04 AM.. Reason: Removed strange language
# 5  
Old 05-06-2010
Can you try this ?
Code:
#!/bin/ksh

while [ 0 -lt 1 ]
do
 if [ -f *.xml ]
 then
  echo "File found" ;
 else
  echo "File not found" ;
  mailx -s "File not found" <email id> ;
 fi
 sleep 900 ;
done

-Nithin.
# 6  
Old 05-06-2010
I typed the command which u gave and I got the below result:

AIX cpaiadba 3 5 00CF6B8F4C00


I have started the script:

What condition I can keep in if loop to get whether the files have been generated in that particular folder or not.

If the script is running at 9:50:00 am , it should get the count of files from 8:50:00 to 9:50:00 AM.

I can get the number files in that particular folder using the below command :

ls filename* | sed 's/_[0-9]*.xml//g' | wc -l

Thanks
# 7  
Old 05-06-2010
Quick question...

Are you always expecting the same amount of files to be generated per hour? For example... will x amount of files constantly be generated each hour?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help Needed with File Checker Korn Shell Script

I am attempting to write a korn shell script that does the following, but I am getting errors. I'm new to korn shell scripting and am not sure what I am doing wrong. Please help with example scripts. Thanks. 1) check for day of the week 2) if day of the week is Monday then check for the... (4 Replies)
Discussion started by: ijmoore
4 Replies

2. Shell Programming and Scripting

Help with korn shell script to get the latest file versions in a directory

I want to write a korn shell script to get the latest three versions for a file in the directory having lot of files with various versions (files with prefix as same but time stamp as suffix) and compress it and at the same time have to remove the remaining versions of the file (other than latest... (4 Replies)
Discussion started by: maheshbabu
4 Replies

3. Shell Programming and Scripting

How to monitor process that consumes 100% during more than 01 hour ?

Hi, On Linux RedHat 5 ( 2.6.18-194.el5 ) I need to monitor process that consumes 100% CPU during more than 01 Hour. Are there command lines ? scripts ? Regards, (11 Replies)
Discussion started by: htaieb1
11 Replies

4. Shell Programming and Scripting

Shell script to monitor new file in a directory and mail the file content

Hi I am looking for a help in designing a bash script on linux which can do below:- 1) Look in a specific directory for any new files 2) Mail the content of the new file Appreciate any help Regards Neha (5 Replies)
Discussion started by: neha0785
5 Replies

5. Shell Programming and Scripting

Validate file count in korn shell script

Hi, I have files in the directory like below which I need to validate if all the required files are present. A_B_001 of 002_time1.txt A_B_002 of 002_time1.txt A_B_001 of 001_time2.txt Scenarios- a)If file with 001 of 002_time1 or 002 of 002_time1 is missing in the folder,script should... (6 Replies)
Discussion started by: aneeta13
6 Replies

6. Programming

create a spool file based on values passed from korn shell to sql script

this is my issue. 4 parameters are passed from korn shell to sql script. parameter_1= varchar2 datatype or no value entered my user. parameter_2= number datatype or no value entered my user. parameter_3= number datatype or no value entered my user. parameter_4= number datatype or no... (5 Replies)
Discussion started by: megha2525
5 Replies

7. Shell Programming and Scripting

Write output to a file using Korn shell script

All, Can anyone please help me with the below scenario in korn shell script. Can anyone please give me some hints to proceed on this. I have a Flat file of the below format. Input file format:... (1 Reply)
Discussion started by: sp999
1 Replies

8. Shell Programming and Scripting

Korn/bash Script to monitor a file a check for specific data

Hi, Im trying to write this script but im stuck on it, basicaly what i want to do is to write a code to verify a log file ( apache log file for example ) and for each new line with specific data , then, output this new line for another file: full ex: output of the server.log is (... (4 Replies)
Discussion started by: Thales.Claro
4 Replies

9. UNIX for Dummies Questions & Answers

korn shell script to keep history of same file

Hello, How do I write a korn shell that will rename file with the current date. What I want to do is, I have a file that is re-written every day. But instead, I want to keep a 14 day history of the file. So I want to write a script that will rename the current file with a date attached to the... (2 Replies)
Discussion started by: watson2000
2 Replies

10. Shell Programming and Scripting

Korn Shell Script - Read File & Search On Values

I am attempting to itterate through a file that has multiple lines and for each one read the entire line and use the value then to search in other files. The problem is that instead of an entire line I am getting each word in the file set as the value I am searching for. For example in File 1... (2 Replies)
Discussion started by: run_unx_novice
2 Replies
Login or Register to Ask a Question