0

I have scheduled a crontab job in AIX 6.1 OS to run twice in an hour which runs for the whole day to process a load.

The load which crontab kicks off needs files to arrive at a particular directory and if the files arrive, I process them.

It so happens that for the 24 times the crontab kicks off my load there would be only 7 times I actually receive the files and for the rest of the times I receive no files and the load reports saying that no files received and I cannot preict when files arrive as it can arrive anytime.

I heard that a DAEMON can be setup in Unix which can monitor for files arriving at a particular destination and call other scripts after that.

I was thinking if it were possible to create a daemon to monitor a particular destination and if files are present, It can call a shell script.

Is this possible, if yes how can I code the daemon. I have no prior experience with daemons. Can anyone clarify.

Dark Matter
  • 2,231
  • 3
  • 17
  • 31
  • It sounds as if you've heard of inotify on Linux; that is designed to alert a process when a directory changes (e.g. because a file arrives) and other similar events. In the absence of a similar system, you can write a process that periodically scans the directory and sees what has changed since the last scan (new files created, old files removed, files changed — whatever you need). The only benefit of a daemon over a separate script is that the daemon can keep a record of the state at the last scan. Yes, it's straight-forward to code up a daemon that does what you want. – Jonathan Leffler Oct 02 '13 at 03:24
  • Since there are a 1000 other questions with the daemon tag, there are bound to be some that answer this question for you. I see four probably relevant questions in the 'Related' list at right: [How do I daemonize an arbitrary script in Unix](http://stackoverflow.com/questions/525247/), [File Monitoring Daemon on Unix](http://stackoverflow.com/questions/5311274/), [Writing a Unix Daemon](http://stackoverflow.com/questions/13243917/) and [Daemons in C — is there a way they're meant to be implemented](http://stackoverflow.com/questions/15025029/). – Jonathan Leffler Oct 02 '13 at 03:28
  • @Jonathan Leffler : Thanks for the comments. I get that I can create a secondary script that runs every minute or something like that and call my actual script only if files are present which will give the effect of daemon but is there a way to run my secondary script a background job instead of scheduling in cron. I went through the links you provided but could not get sense of how I can do that. At the end of the day I want to stay away from cron. – Dark Matter Oct 02 '13 at 05:49
  • The first link seems to discuss your situation pretty accurately. You want to daemonize a script; it explains how to do it. You wrap the body of the script in a `while true; do ...; done` loop. You run it via `nohup` after sending the output where you want it to go. That's the long and the short of it. If you're willing to delve into C, then I have a `daemonize` program that I wrote to run another program (that didn't daemonize itself properly) as a true daemon. Then I got the bug in the other program fixed so I didn't have as much need for it any more. See my profile for contact info. – Jonathan Leffler Oct 02 '13 at 06:23
  • See also [Is there a good reason to write my own `daemonize()` function?](http://stackoverflow.com/questions/3720439/is-there-a-good-reason-to-write-my-own-daemonize-function-instead-of-using-daemo/3720789#3720789) There are a couple of good links in [Creating and using a C/C++ Daemon on Linux or Unix](http://stackoverflow.com/questions/6323304/creating-and-using-linux-unix-c-c-daemon/) — the link to the TED talk is not directly relevant, but is interesting. – Jonathan Leffler Oct 02 '13 at 06:39

0 Answers0