Best practise for keeping cronjobs across 2 servers in sync


 
Thread Tools Search this Thread
Operating Systems Solaris Best practise for keeping cronjobs across 2 servers in sync
# 1  
Old 11-03-2016
Best practise for keeping cronjobs across 2 servers in sync

Hi all,

I have 2 server A and B. B is acting as standby for A.
The cronjobs running in A must not be run in B until failover.
The activation of cronjobs in B can be manual.

In server A, I am doing the following

1) create a cron/job script that does
"crontab -l > cronjob.txt" and scp the cronjob.txt to server

2) keep all my cronjob scripts in a folder /export/home/xxx/scripts and doing a daily rsync to server B in the same path

In event of failover, I will just open cronjob.txt, crontab -e and copy all the output in.

Am I doing this correctly ? or there is a more efficient way to do so ?

Regards,
Noob
# 2  
Old 11-03-2016
Are there any cron jobs on your system that need to run on the stand-by server? If not, have you considered disabling cron on the stand-by server and enable it when there is a switch from stand-by to active.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 11-03-2016
Do you have a shell command that shows if active or standby?
Then you can have identical crontab entries.
For example your shell command is "activecommand" and has an exit status zero when active, otherwise non-zero.
Code:
* * * * * if activecommand; then actualcroncommand; fi

This User Gave Thanks to MadeInGermany For This Post:
# 4  
Old 11-07-2016
Quote:
Originally Posted by Don Cragun
Are there any cron jobs on your system that need to run on the stand-by server? If not, have you considered disabling cron on the stand-by server and enable it when there is a switch from stand-by to active.
Hi Don,

Thanks for your reply and sorry for coming back late.
Yes, there are certain standalone cronjobs that needs to be run on the standby server. Thus i am not able to disable cronjob entirely.

Hence my thinking was to sync the cron scripts over and cron entries from the primary over. When there is a failover, i will manually add them (cut/paste) into the crontab in standby

Not sure if there is any other better way to do so..

Regards,
Noob

---------- Post updated at 12:48 PM ---------- Previous update was at 12:46 PM ----------

Quote:
Originally Posted by MadeInGermany
Do you have a shell command that shows if active or standby?
Then you can have identical crontab entries.
For example your shell command is "activecommand" and has an exit status zero when active, otherwise non-zero.
Code:
* * * * * if activecommand; then actualcroncommand; fi

Hi MadeInGermany,
Thanks for your insight !
I can make a simple function/script that return active or standby, but how do we keep the cron entries in sync on both servers ?

is it a manual work (e.g. when you add in nodeA, do the same on nodeB) ?

Regards,
Noob
# 5  
Old 11-09-2016
You still need to maintain identical crontabs on both servers.
Manual work might be okay.
If you have often changes, and if you have a shared directory say /shared/dir/ then you can go for another entry, for example (every hour)
Code:
1 * * * * ctab=/shared/dir/crontab.txt; if activecommand; then crontab -l >$ctab; elif [ -f $ctab ]; then crontab - <$ctab; fi

Note: most Unix crontab commands read from stdin by default, without the - argument.
This User Gave Thanks to MadeInGermany For This Post:
# 6  
Old 11-10-2016
thanks madeingermany!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Odd(?) shell script practise

Hello, I often stumble over a common shell coding practise. Example 1: #!/bin/sh # # Licensed Materials - Property of IBM # Rational ClearCase # (C) Copyright IBM Corp. 1999, 2010. All Rights Reserved # US Government Users Restricted Rights - # Use, duplication or disclosure restricted... (4 Replies)
Discussion started by: MadeInGermany
4 Replies

2. Solaris

Client does not sync date with ntp servers

We had a network problem a couple of days before that caused 1 interface to down and up. But today I have noticed that our date is wrong, our system have 4 servers and the other 3 are OK. I used <date> command, the result is: Fri Jan 2 17:57:55 ICT 1970 I have tried set date to be the same as... (3 Replies)
Discussion started by: salvation3103
3 Replies

3. UNIX for Advanced & Expert Users

How to Sync two servers

Hi All, want to sync. two servers , both are having solaris os. If am updating any thing in one server , it will automatically sync. with the other server . Is it possible , if so den how ? (3 Replies)
Discussion started by: natraj005
3 Replies

4. Web Development

How do you sync tables in mysql between two different servers?

Hi all, I have 2 mysql databases running on two different servers (both can be accessed via ssh to each other). If I have say table ABC on server 1, how can I sync it with table ABC on server 2 if the number of records is different? Both databases are the same structure though server 2 has... (2 Replies)
Discussion started by: muay_tb
2 Replies

5. Shell Programming and Scripting

Is it bad practise to exit in function?

Question is title, I don't understand why all examples I am reading return constants error values instead of just exiting under certain conditions... then back in main script test return value and exit if true, to me seems like a lot of extra typing and test conditions which can make for bulky and... (5 Replies)
Discussion started by: gcampton
5 Replies

6. Shell Programming and Scripting

sync files from two different servers.

I have a directory called UNIX 1 which contains 2 files and uploaded into two different servers. Now I want to check whether the directory contains both the files. If not, then need to sync the directory. Please let me know how to do that in shell scripting. (2 Replies)
Discussion started by: madan1
2 Replies

7. Red Hat

how to find the red hat servers in time sync

Hi all, Before i'm going to install application on my RHEL servers, I just wanted make sure servers in time sync. How can I find it. Thanks. (1 Reply)
Discussion started by: s_linux
1 Replies

8. Solaris

Sync to Green vs. Separate Sync

Hi all....I have a Sun Ultra2 that I want to use with my PC monitor. I have purchased an adapter that does not work and I was told I need to change my video card setting (if I can) to Separate Sync.....my Monitor product number ends in 1343......I am running SunOS 5.7 ......anyone have any ideas? ... (0 Replies)
Discussion started by: psantinello
0 Replies

9. UNIX for Dummies Questions & Answers

Need Unix Terminal for practise on Rental basis ...plz help!

Hey Guys,, Have just got started with Unix , I need UNIX Terminal to practise commands. Does any website host such services ? Happy Holidays... (9 Replies)
Discussion started by: rrover1977
9 Replies

10. AIX

Cronjobs

We recently upgrade from AIX 4.3.3 to AIX 5.3, We noticed that some cronjobs that run for our programmers did not fire off this morning. You can crontab -l and -e and see the jobs. Did AIX 5.3 change something? Thanks Mike (1 Reply)
Discussion started by: mcastill66
1 Replies
Login or Register to Ask a Question