Deploying Cronjob to multiple servers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deploying Cronjob to multiple servers
# 1  
Old 12-03-2010
Deploying Cronjob to multiple servers

I figure that this is a shell scripting issue so I'll post here.

I'm attempting to deploy a cronjob to a variety of servers, some 200-odd, of all walks of life. Mostly AIX, but some Solaris, some HP-UX, some Linux (of varying distributions), etc. I initially thought about utilizing a mass deployment with a scripted rsh or ssh command, echoing in an appended line that contained the cronjob and executing a refresh/restart of the cron service. But that won't work, so I'm stuck with another method, utilizing a vi command. This is supposed to be doable but I'm having some trouble visualizing it. If someone could get me started in the right path that would be great, or provide a script that they've used in the past.

Secondly, if simply echoing/inline editing crontab entries won't work, what will I need to do if I need to edit the file after the initial deployment and adjust the entry for whatever reason (syntax error, change the execution time/date, etc.)? A friend of mine suggested using a perl script that invokes a vi-style search-and-replace function but will these changes be seen by cron on these systems or not? If not, is there another method recommended?
# 2  
Old 12-05-2010
Create an ed script, call it mycron:
Code:
1a * * * * * /path/to/myscript > /tmp/logfile 2&>1
.

/var/spool/cron/crontabs is the directory for Solaris crontabs. You will need an OS-specific variant of the script below.

This script assumes you are able to write the crontab, and that you have ssh keys installed. It also makes a lot of assumptions about your boxes - ie all of the solaris boxes have the same usernames, permissions, etc.

Code:
#!/bin/ksh
#ip.dat is a list of nodes of one flavor of OS
while read nname
do
sftp $nname <<EOF
   put mycron
   exit
EOF
ssh $nname '(cat mycron %&& echo "w" ) | ed - /var/spool/crontabs/someusername'

vi is based on ed. ed will not break your crontabs. Do not put too much faith in my example ed script, test it first.
# 3  
Old 12-07-2010
Thank you for the reply.

It doesn't quite answer my original question. The big one: will any changes done to the crontab file manually (through ed/vi/echoing text in/etc.) cause cron to see those changes? I've been told by our SME that they won't, at least not in Solaris. What about other OSes, like AIX, Tru64 or Linux?
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to apply the update statement in multiple servers on multiple dbs at a time .?

Hi , Can any please help the below requirement on all multiple servers and multiple dbs. update configuration set value='yes' ;1) the above statement apply on 31 Databases at a time on different Ip address eg : 10.104.1.12 (unix ip address ) the above ip box contains 4 db's eg : db... (2 Replies)
Discussion started by: venkat918
2 Replies

2. UNIX for Beginners Questions & Answers

ssh multiple servers

Hi folks. I'm pretty new to unix, while I'm learning a lot I'm finding bash scripting quite confusing. Im sure it's not really, my head just hasn't clicked with it. Anyway, I need a script to loop the ip addresses stored in a file and run a "pgrep <process>" and return the pid or some... (2 Replies)
Discussion started by: MuntyScrunt
2 Replies

3. UNIX for Advanced & Expert Users

Help with credentials when using Grep across multiple servers

Hello all, I need some help with a script I have been working on. I was wanting to know if it is possible to add authentication to it for each server it runs across? The credentials are all the same on each server. This is what I am using so far and it seems to work. I am trying to avoid... (3 Replies)
Discussion started by: Smorgen
3 Replies

4. UNIX for Dummies Questions & Answers

SSH into multiple linux servers

Hi All, Okay, I need help. I need to ssh in to multiple linux servers execute certain commands and get them to email and print on the screen when the script is being executed. So below is my script. Its not working :-(. #!/bin/bash #linux/UNIX box with ssh key based login... (7 Replies)
Discussion started by: xytiz
7 Replies

5. UNIX for Advanced & Expert Users

Help Me - How to grep in multiple servers

Hi All, I need help , Regarding the keyword search in multiple servers at a time . we are desiging a search website . we have a multiple servers and each of the server have 3 instances having Unix compressed files.Our requirement was we need to search the particular key word for eg. we need to... (7 Replies)
Discussion started by: prasad00124
7 Replies

6. Solaris

Centralize multiple servers administration

Hello, this is my first post, i´m trying to get some help on this issue. I´m looking for a software product (maybe SUN or TIVOLI) that provide me help on doing administrative tasks involving solaris, aix , linux & HPUX machines. This tasks are user/password creation/modification, SSH rights,... (1 Reply)
Discussion started by: amedran
1 Replies

7. Shell Programming and Scripting

rsh to change multiple ip in multiple servers?

good day. i jsut wanted to know what is the best script or the best way changing a lot of Ip's in all servers. Do you have any idea? im using awk to change IP,what if, you have lots of servers. You need to change it one by one? It will take time to change it manually. (2 Replies)
Discussion started by: kenshinhimura
2 Replies

8. Shell Programming and Scripting

ftp to multiple servers

Hi folks. I am writing a ksh ftp script. The problem is, I need to transfer the files to several different servers. Is there a way to close a connection and move on to the next in one script or do I need to write a separate script for each one? Thanks, kristy (2 Replies)
Discussion started by: kristy
2 Replies
Login or Register to Ask a Question