-1

A feature will be launched which will create logs as the run proceeds. So, I have to write a script which will keep on checking a directory during runtime of the about feature if there are any log files created or no and incase if I see the logs being created, I will do further actions. The tricky part here is I do not have access to watch, cron jobs or anything like that at customer site so any other suggestion would be appreciated. Also, I cannot install any python libraries, so I need something very basic.

I haven't yet tried but looking to see if any function exists, I am planning to use while loop to keep monitoring the directory.

  • Don't reinvent the wheel (unless your boss is making you <-;!) . https://stackoverflow.com/a/19733629/620097 can help. Good luck. – shellter Jan 27 '23 at 23:32
  • Hey I saw the command inotifywait but it says "command not found". I gues this doesnt work in our environment too. – user19028585 Jan 28 '23 at 00:03
  • what do you get with `uname -srv` ? Also, it may be in a "special" directory not on your normal path.. It may also just be named as `inotiify` AND there are other similar feature packages. See you can get it installed, better use of your time. Ask around at your work site. AND there is almost certainly code someplace here on S.O. that will do this, so sharpen up your searching skills (-;! Good luck. – shellter Jan 28 '23 at 00:11
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 28 '23 at 09:38

1 Answers1

1

If you cannot convince the client to install inotify-tools in order to have access to inotifywait, then you need to keep track of not only the existence of an output file, but, more important, is the output file closed (is the process finished with that file).

In other words the process creating the file would have a second "flag file" (call it ${process_name}.writing) which would be created before output and removed when output completed.

As for conditional logic, if output.txt exists and ${process_name}.writing does not, then the output.txt is complete and usable.

You can always consider use of the flock utility to test/assign reserved use of file in order to ensure no conflicts in acquisition of "closed" files.

Eric Marceau
  • 1,601
  • 1
  • 8
  • 11