Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Makin Crontab cluster aware

Status
Not open for further replies.

lhg1

IS-IT--Management
Mar 29, 2005
134
DK
Hi

I'm moving from a singel node system to a cluster system.

And I have to move a lot of crontab enteries, and I wondering if anyboddy have any good ideers, on how to make them cluster aware(only run on the node where the cluster package is running)

One of the options that I was thinking about.
Was to make a script that checks if the package is running on the server and then putting this in front of all the script in the cron. But it will give me problems when these scripts are executede with special caracters.

ex. a posible cron
Code:
* * * * * /home/monitoring>> /home/log/`hostname -s`_monitoring_`date +\%Y\%m\%d`.log 2>&1

Could have a script that would execute the command only if the right cluster package is running on the node.

ex.
Code:
* * * * * /home/ClusterAware.sh /home/monitoring>> /home/log/`hostname -s`_monitoring_`date +\%Y\%m\%d`.log 2>&1

But I can't figure out how to make the ClusterAware.sh script in a way where it can handle the special caracters.

I realise that I cound build the cluster aware into every script, but that is not quite what I want.

Hope some one can help, or anyboddy that have tryede something simular.

/LHG
 
Which special characters is supposed to handle ClusterAware.sh ?
The IO redirection should be performed by the shell spawned by cron.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
My ideer is the have ClusterAware.sh execute the commands/scripts that are in the current cron tab.

ex. of the ClusterAware.sh script
Code:
if [ $cluster = "online" ]      #this is just an example
then
eval $*
fi

and this is the script that shoud be executede names examplescript.ksh
Code:
echo $1

the crontab could look something like this.
Code:
* * * * * ./ClusterAware.sh ./examplescript.ksh 'the is the first parm' >> ./log_`date +\%Y\%m\%d`.log

but this doesn't work becourse of the ' is not usede in the examplescript.sh, in the logfile only the is entered. And I don't know how to get ' to work.

Also I'm not sure witch special caracters that will work and witch won't - and the cron that I'm suppose to move is not controlede by me, so I need to know the limits and what I can acieve.

I don't understand this
The IO redirection should be performed by the shell spawned by cron.

 
Why using the eval builtin ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Good question, its only becourse I've tryede different things.

In this case it does not matter.
 
What about this (without eval in the script) ?
* * * * * ./ClusterAware.sh ./examplescript.ksh '\"the is the first parm\"' >> ./log_`date +\%Y\%m\%d`.log

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Still only takes the first one, in this case:
\"the

/LHG
 
Wrap the crontab entry in a script which checks for the existence (for example) of the process or processes which handles the cluster.

I want to be good, is that not enough?
 
The method I use is to make ClusterAware.sh return a true or false value (i.e. exit 0 for true, cluster is active on this node, and exit 1 for false).

Then you can use it like this:

Code:
* * * * * ./ClusterAware.sh && ./examplescript.ksh 'the is the first parm' >> ./log_`date +\%Y\%m\%d`.log

Annihilannic.
 
Hi Annihilannic

I not quite sure what && does in the command line? - could you explain?

/LHG
 
man sh said:
The symbol && causes the list following it to be executed if the preceding pipeline succeeded (returned a 0 exit status).


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top