Operating System - HP-UX
1753657 Members
5699 Online
108798 Solutions
New Discussion юеВ

Re: How to enable crontab for user only on active node?

 
SOLVED
Go to solution
MAD_2
Super Advisor

How to enable crontab for user only on active node?

We have a setting where applications run active/failover by means of either VCS or HP/SG.

With these, I would like to hear about ideas on how to make crontabjobs only to be active on the active nodes and therefore follow the application where it is active? I am open to hear suggestions about solutions used in other places.

This scenario is only on test systems as our production systems are not using cron but instead use an external batching mechanism that goes directly to the respective node to launch the jobs as required.


MAD
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
7 REPLIES 7
TwoProc
Honored Contributor

Re: How to enable crontab for user only on active node?

You could easily add commands to the package to move around/copy around/rename the cron.allow file in /usr/lib/cron/cron.allow.

This file controls who can run cron. You could do whatever you need to the file when the package moves around.
We are the people our parents warned us about --Jimmy Buffett
Steven E. Protter
Exalted Contributor

Re: How to enable crontab for user only on active node?

Shalom,

build a script into the package that changes the the cron.allow and/or cron.deny list

Or if you will permit the user editing priviledges then copy the schedule in /var/spool/cron back and forth from node to node. Again, this is best done in the package script.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
A. Clay Stephenson
Acclaimed Contributor

Re: How to enable crontab for user only on active node?

Rather than trying to have control scripts change crontabs on the fly, I find it much easier to run the same cron scripts on all potential adoptive hosts and to let the script itself determine if it should actually execute or exit immediately. I'll assume that your package has a volume group associated with it so your cron'ed scripts needs to check for the existence of a file under this VG.

e.g.

#!/usr/bin/sh

typeset CHEKFILE=/xxx/yyy/myfile.dat
typeset -i STAT=0

if [[ -f "${CHEKFILE}" && -r "${CHEKFILE}" ]]
then
echo "I'm the active node"
# do your stuff here and set ${STAT}
# to whatever you like; 0 => ok
fi
exit ${STAT}

----------------------------
No crontabs have to be moved, nothing has to change. All you have to do is install the scripts and the appropriate crontab entry on all potential nodes and you are done.
If it ain't broke, I can fix that.
MAD_2
Super Advisor

Re: How to enable crontab for user only on active node?

Although I sort of like this last approach, it's unconceivebly complex to attempt to change current scripts, since there are hundreds, potentially thousands, as the appllications are also too many.

Each application has its own crontab (about 5-10 applications per each host). Each application can have a crontab with about 1-50 jobs in it, so it's unfeasible to consider changing the scripts, as I also don't have control over them.


MAD
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Geoff Wild
Honored Contributor
Solution

Re: How to enable crontab for user only on active node?

2 ways - either via a script in the custome defined start/end functions or, in cron itself - have it set to only execute if say a filesystem is mounted.

I do the latter like so for example:

# clean up old PCT data
30 5 * * * [ -d /oracle/PROD/920_64 ] && /usr/local/bin/pct.clean >/dev/null 2>&1

/oracle/PROD/920_64 does not exist on my inactive node, as /oracle/PROD is a mounted file system.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
A. Clay Stephenson
Acclaimed Contributor

Re: How to enable crontab for user only on active node?

Well, when you think of this after the fact then virtually any scheme is complex. This is the sort of thing that should have been designed on the front end. You are a victim of your own poor planning --- or it is your job to clean up someone else's mess.

When you mention thousands of scripts then this suggests an automated method of changing all the scripts. It should be rather easy to create a wrapper script that is called by cron that in turn calls your existing scripts or simply exits.
If it ain't broke, I can fix that.
MAD_2
Super Advisor

Re: How to enable crontab for user only on active node?

I very much like your approach Geoff, and I think it may not be so extremely painful to implement... Unfortunately it is like case #2 mentioned by Clay:
"it is your job to clean up someone else's mess."

Thanks... I'll leave this open for another couple of days and then close it, in case there are other bright suggestions floating around.

This place is always an excellent start for great ideas.

MAD
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with