Prevent file from being mailed multiple times from a job


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Prevent file from being mailed multiple times from a job
# 1  
Old 11-14-2006
Prevent file from being mailed multiple times from a job

We have a ksh which runs once every 15 minutes. Based on a certain condition (for invalid data) we are spooling a file and if the file is of length greater than 0 bytes, then we are mailing this file to a group of users. Upon receiving the file, users correct the data so that on its next run the same data is not selected and the file spooled becomes 0 bytes and hence is not mailed across.
But, it mostly happens that users take more than 15 minutes to correct the data and hence this job creates the same file and mails it to the uses again.

What I am looking for, is there a counter logic which I can set and which will allow me to send the file only once of it is greater than 0 bytes.

Best would be - once the file is created with more than 0 bytes for the first time, it will be sent only once(i.e for the first time) and after that, say, for the next 2 hours( which implies 7 more cycles), this file, even if gets created will never be mailed at all.

Thanks,
Sree
# 2  
Old 11-14-2006
You could, when you mail the file, move it to file.old and then in the next run, if there is a file.old, compare it to the new file that is just made. If they are the same, don't mail it. If they are different, add the new changes to the file.old and send/mail the new changes and then move the new one to file.old. This way, you don't lose any info that needs to be corrected, the users will be getting data that is new.

Once you have a run with no changes (zero bytes), you could remove file.old for future runs.
# 3  
Old 11-14-2006
Hi,

Thanks RTM. This seems to be the best solution so far. I have designed the flow of the algorithm based on this solution - here it goes -

Code:
--*******************************************--
| Non-Repeating Mailing Logic in the program: |
--*******************************************--

---------------------------------------------------------
|BEGIN PROCESSING BLOCK:				|
---------------------------------------------------------


Check for existence of File A_Old created on the previous day.
 
 If File A_Old was created on the previous day, then
 
    Remove File A_Old.
 
 Else, 

1. Create File A.

If File A > 0 bytes, then

   2. Check whether File A_Old exists or not.
   
   If File A_Old does not exist, then     -- (this implies this is the first time mailing process)
   
   2a(i). Copy File A to File A_Old.
   2a(ii). Mail File A to the users.
   2a(iii). Remove File A.
   
   If File A_Old does exist, then      -- (this implies we might have already mailed the Rejects file)
   
   2b. Compare File A with File A_Old.
   
       If both the files are the same, then
       
       2b(i). Skip Mailing process.
       
       If the files are different, then
       
       2b(ii). Copy File A to File A_Old.
       2b(iii).Mail File A.
       2b(iv). Remove File A.

If File A = 0 bytes, then

   Skip entire mailing process.
   
---------------------------------------------------------
|END PROCESSING BLOCK:					|
---------------------------------------------------------

However, for this to go right, I need to know how can I find whether a file is created on the previous day or not(i.e in any way can the file creation timestamp be retrieved and comapared against the current date), if the timestamp is of the last day, then I would be deleting the old file, otherwise retain it.

Thanks again, RTM .

-
Sree
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Replace string and create new file multiple times

First of all, apologies if this has already been answered elsewhere. I haven't quite been able to find what I'm looking for yet, so hopefully this won't come across as repetition. I have a file consisting of ~100 nearly identical lines, each of which contains multiple instances of the string I... (11 Replies)
Discussion started by: pseudo.seppuku
11 Replies

2. UNIX for Dummies Questions & Answers

How to check if the same file exists multiple times?

Hi Team , Is there a way I can check to see if the same file say , test.dat exists multiple times in the directory path ? Please help. Thanks Megha (5 Replies)
Discussion started by: megha2525
5 Replies

3. UNIX for Dummies Questions & Answers

copying same file multiple times with different names

hi, I am copying a file from 1 folder to another in /bin/sh. if the file already exists there, it should get copied as filename1. again if copying next time it shouldget copied as filename2.. , filename3..so on.. The problem is i am able to get uptil filename1.. but how do i know what... (6 Replies)
Discussion started by: blackcat
6 Replies

4. Shell Programming and Scripting

Cron to schedule job at different times

Hi, I want to run cron scheduler to run some script at different times of the day.But these times don't have some fix intervals. So how we can run jobs at 6:30AM, 1:00PM and 4:30PM everyday. Please help. Thanks Neeraj (2 Replies)
Discussion started by: apjneeraj
2 Replies

5. Shell Programming and Scripting

Append some text to a file multiple times

Hi, I have a text file like Version=abc Tab=1 URL GOTO=www.abc.com/board=1 some text... I want to run a loop x no of times and append to the text file above text but URL GOTO should be www.abc.com/board=2 then 3,4...etc till x. Kindly help (2 Replies)
Discussion started by: krabu
2 Replies

6. Shell Programming and Scripting

call a passwd file to a script multiple times

Hello everybody, I have a requirement in my script.. When i'am executing a script, it'll ask a passwd of some service account.. I need to pass it to the script through a zipped file when it asks for it. The script can be executed by more people many number times. So for securty purpose, it... (1 Reply)
Discussion started by: raghu.iv85
1 Replies

7. Shell Programming and Scripting

Cron job to prevent simultaneous script

I'm using a shared server on Hostgator (Linux CentOS). I'm trying to set a cron job using the Control Panel that will check if its already running before starting a new one. I've tried the following... * * * * * && but I get this error emailed to me... /bin/sh: line 0: Any... (5 Replies)
Discussion started by: tech9821
5 Replies

8. Shell Programming and Scripting

Output section of file between two expressions multiple times

Attached is the exact ouput of a vmware VDR log file I am working with but what I am trying to achieve is as follows: I need to output sections of the file using the string "Normal backup" as the start and "Duration" as the end to seperate files so I can then manipulate them further to create... (2 Replies)
Discussion started by: jelloir
2 Replies

9. Shell Programming and Scripting

How pull the Data from the file and should be mailed

Hi All, I need to pull the data from a file from 2 set of directories & should be mailed. I have a code , it is failing for some reason. Do somebody correct me where my script is going wrong. Directories: 1st Set of Directory /176_PS/Transactions/**/syslog.log ** : prd1 prd2... (2 Replies)
Discussion started by: raghunsi
2 Replies

10. AIX

Locking a file when using VI to prevent multiple-edit sessions by diff users

At the office, we often have to edit one file with VI. We are 4-6 workers doing it and sometimes can be done at the same time. We have found a problem and want to prevent it with a file lock. Is it possible and how ? problem : Worker-a starts edit VI session on File-A at 1PM Worker-b... (14 Replies)
Discussion started by: Browser_ice
14 Replies
Login or Register to Ask a Question