Setting up a Daemon in UNIX

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 predict 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 provide a sample for the same.

with bash:

#!/bin/bash
while true
do
    # add code to monitor dir here and take same action
done
nohup monitor.sh &
1 Like

Remember that you would have to be sure that the fail arrival had completed before you take any action. We achieve this by each process that delivers a file having to send a follow up flag. If the file in question is inventory then we would watch for inventory.ok or something similar of your choosing to confirm that the delivery has completed. That way, your sending process can also perform some checks that the entire file has been delivered.

We have some large files that go across public networks so can take 3 hours to transmit, and errors (and therefore a re-send) occur a few times a month. Only when we are happy that our data send is complete to we send over the OK file and processing on the other side triggers in.

Robin
Liverpool/Blackburn
UK

1 Like