0

So I have successfully developed a filewatcher script that's running fine. The script reads a file which contains list of input files (full path to the file), delimited with | and other information. Something like this:

/path/to/file/1.txt|600|900|Team1|team1@email.com
/path/to/file/2.txt|630|930|Team2|team2@email.com
/path/to/file/3.txt|2300|2359|Team3|team3@email.com

etc. First one is the file, second and third are timings between which the file usually comes, fourth is the team responsible for the file and 5th is their email.

The script runs every ten minutes in the background 24/7 and compares the current timings with the second and third column, if the current time falls in between these timings, checks if the file is there or not. When the end time (column 3) is less than ten minutes and the file hasn't arrived, then an email is sent to the team that the file is missing.

To check if a file arrived after it's defined time, I've set another condition which checks the endtime - current time value. If it is negative, then it checks if the file came after and missed it's SLA or not. If the file arrives late, the script sends an email saying that the SLA was missed for that file. It calculates the "SLA" missed time using current time-end time (3rd column). Example if the first file comes at 930, then (930-900) is 30 minutes late. All these works fine.

I have just one problem. If you look at the last line in my example - the timings end at 2359 and I can't calculate if the file arrived after 2359 (as that's the highest time in a day and this minus any value won't produce a negative value). Obviously, I also cannot calculate the right SLA miss time if it comes later than that. Example if the file comes at 100 hrs, then the script thinks that the file came before the SLA time and doesn't send any alert (100-2359 is negative).

How can I overcome this?

  • 2
    Rather than having a 'start time' and 'end time' for the acceptable delivery window, can you switch to a 'start time' and 'window duration'? Then you can probably more easily make the comparison after you convert the current time to epoch time, add the number of seconds specified by the window, and compare that to the epoch-converted delivery time. – DopeGhoti Oct 6 '17 at 21:25
  • Ah ha! Interesting. I will check this out, but this means I have to rewrite the entire code (300 lines :-() with new logic. Thanks for the suggestion, @DopeGhoti – mathB Oct 6 '17 at 21:30
  • @DopeGhoti if there's no other options, can you put this as an answer so that I can accept it? – mathB Oct 9 '17 at 18:31
1

You might need to re-engineer the script, but an easier way to track this sort of thing involved availing yourself of conversions to and from 'epoch' time, and from working with a 'window duration' rather than a 'window start time and end time' Then you can more easily make the comparison after you convert the current time to epoch time, add the number of seconds specified by the window, and compare that to the epoch-converted delivery time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.