Linux + create simple watch dog process in shell script

failoverclusterkshlinuxshellwatchdog

I need to create watch dog process (will run in linux version 5.x)
that look all time on /etc/cluster.cf file

And if the process matches the string: machineA_is_active in the cluster.cf file

Then this process will execute other script

My question is – how to run this process in way that process will up and running all time that Linux is up –

and in case this process is down need to startup this process again

So please advice what the basic structure for this scenario ?

(I will happy if I get real example)

Best Answer

I'd not recommend trying to keep a process running all the time to do this. There are more simple methods. Your machine should have cron running which is a periodic task scheduler. You can schedule a process to run periodically, as frequently as once per minute to check the contents of the file and do what needs to be done. You might add something like this to the crontab:

* * * * * /path/to/yourscript

see man 1 crontab and man 5 crontab and man 8 cron for more information about cron.

Even better is to use incron which allows you to specify a process to be run any time this file is changed. If you have incron installed you'd add something like this to the incrontab:

/etc/cluster.cf IN_MODIFY /path/to/your/script

Saying that anytime /etc/cluster.cf is modified, run your script. see man 5 incrontab and man 1 incrontab