Operating System - HP-UX
1832567 Members
5164 Online
110043 Solutions
New Discussion

Re: Syncing Crontab in a Service Guard Environment

 
David Land
Frequent Advisor

Syncing Crontab in a Service Guard Environment

I have a two node Service Guard environment. I would like to keep the crontab between both systems in sync.

How do you go about keeping crontab between both systems in sync?

Thanks,
9 REPLIES 9
A. Clay Stephenson
Acclaimed Contributor

Re: Syncing Crontab in a Service Guard Environment

As root (or su-ed to the other cron users):
TDIR=${TMPDIR:-/var/tmp}
TFILE=${TDIR}/X${$}.cron

remsh hostB crontab -l > ${TFILE}
crontab < ${TFILE}
rm -f ${TFILE}

Add a bit of error checking and that's it.
If it ain't broke, I can fix that.
Sundar_7
Honored Contributor

Re: Syncing Crontab in a Service Guard Environment

How about rdist or a seperate cron job for syncing Crontabs.

if [ $(hostname) != "server2" ]
then
for USER in $(cat /tmp/crontablist)
do
rcp /var/spool/cron/crontabs/$USER server2:/tmp/${USER}_cron
remsh server2 "su ${USER} -c "/usr/bin/crontab /tmp/${USER}_cron"
remsh server2 rm /tmp/${USER}_cron
done
fi
Learn What to do ,How to do and more importantly When to do ?
A. Clay Stephenson
Acclaimed Contributor

Re: Syncing Crontab in a Service Guard Environment

Rcp/rdist will bring the files over but it will not refresh the cron daemon's current internal data structures. For that you need the crontab command which copies in the new file AND sends a SIGHUP to the cron daemon.

You could rcp the files over and then send a kill -1 to cron.
If it ain't broke, I can fix that.
Julio Yamawaki
Esteemed Contributor

Re: Syncing Crontab in a Service Guard Environment

David,

In our environment, instead of sync'ing crontabs, we made separate crontabs for different users. So, as the package goes up, the correspondent crontab is putting to work.
Victor Fridyev
Honored Contributor

Re: Syncing Crontab in a Service Guard Environment

Hi,

What about the following ?
To set node1 as a master and to run
#!/usr/bin/sh
LIST_USERS="root admin whatever"
for USER in $LIST_USERS ; do
rcp /var/spool/cron/crontabs/$USER node2:/var/spool/cron/crontabs/.
done
remsh node2 "/sbin/init.d/cron stop"
remsh node2 "/sbin/init.d/cron start"

Regards
Entities are not to be multiplied beyond necessity - RTFM
David Land
Frequent Advisor

Re: Syncing Crontab in a Service Guard Environment

Doing the RCP will probably work, but how do you send a kill -1 signal to Cron?
Marvin Strong
Honored Contributor

Re: Syncing Crontab in a Service Guard Environment

ps -ef | grep -v grep | grep cron | awk '{print $2}' | xargs kill -1

thats one way to HUP cron. assuming you don't have any other process that match cron as the grep pattern.

Re: Syncing Crontab in a Service Guard Environment

I take a slightly different approach to this, so I can associate a crontab with a package:

1. Create a crontab file on shared storage associated with the package.

2. in the package start scripts update the crontab with this file

3. in the package stop scripts remove the crontab

4. As sometimes the node will fail while the package is running, we also need a startup script in /sbin/init.d linked to /sbin/rc2.d that runs before the cluster starts and removes all crontabs associated with packages (when the package starts, they will get added back)

5. Make sure that there is a comment at the start of the crontab that reads something like:

# WARNING: Do not update using crontab -e
# Instead, update file /shareddisk/myuser/crontab and run
# crontab /shareddisk/myuser/crontab

HTH

Duncan

I am an HPE Employee
Accept or Kudo
Trond Haugen
Honored Contributor

Re: Syncing Crontab in a Service Guard Environment

If the purpose of syncronizing them is linked to the packages I would suggest having the package scripts putting in the crontab entry when started and removing it when stopped.

Regards,
Trond
Regards,
Trond Haugen
LinkedIn