1753814 Members
8064 Online
108805 Solutions
New Discussion юеВ

adding entry in cron

 
Kwhite_1
Advisor

adding entry in cron

Hello People,

I need to add a cronjob. Now I need to add this to over 600 servers.It would be difficult to login on each and every server and do a crontab -e and add the job.Do we have suggestion to append this new job on all the servers.
6 REPLIES 6
Pete Randall
Outstanding Contributor

Re: adding entry in cron

The crontabs are stored in a plain text file located at /var/spool/cron/crontabs/user_name.

It should be a relatively simple matter to set up a script that would echo the new entry, appending it to the various machine's crontabs. Something like this:

echo "00 05 * * 1 /opt/ignite/bin/check_recovery" >> /var/spool/cron/crontabs/root

would do it. Then you just need to figure out how to do that on all your servers. Maybe a "for" loop?

for SRVR in `cat server_list`
do
echo command here
done



Pete


Pete
James R. Ferguson
Acclaimed Contributor

Re: adding entry in cron

Hi:

You could 'ssh' or 'rsh' into your servers and then do (for example):

# echo "* * * * * date" >> /var/spool/cron/crontabs/root
# /sbin/init.d/cron stop
# /sbin/init.d/cron start

Regards!

...JRF...
Ivan Krastev
Honored Contributor

Re: adding entry in cron

And don't forget to create a backup copy of the crontab file in case of script errors.
Multiplying error on 600 server will cost you lots of time.
First test your script on 1-2 server.

regards,
ivan
Dennis Handly
Acclaimed Contributor

Re: adding entry in cron

>Pete: The crontabs are stored in a plain text file located at /var/spool/cron/crontabs/
>It should be a relatively simple matter to set up a script that would echo the new entry, appending it to the various machine's crontabs.

Do NOT do this! cron has no idea you did this so it will NOT see the new entry.

A better solution would be to use "crontab -l", then your echo, then "crontab file" to reread the new file.

>for SRVR in `cat server_list`

And of course you remove evil cats by:
for SRVR in $(< server_list); do

>JRF: # /sbin/init.d/cron stop

That would be better but why not do the obvious and use crontab?
James R. Ferguson
Acclaimed Contributor

Re: adding entry in cron

Hi:

I'm sorry, what in our answers didn't satisfactorily answer your question?

Regards!

...JRF...
Peter Nikitka
Honored Contributor

Re: adding entry in cron

Hi,

perhaps a summary of all of the valuable answer will help Kwhite ...

NB1: a plain 'remsh' command will read from stdin and that may have 'mysterious' impact for loops triggered by stdin ...
NB2: I'd keep the temporary files as a backup of the previous crontab entry.

rem=ssh # or rem=remsh
for svr in ($do
print 'MM HH DD . . . cronentry' |
$rem $svr '(crontab -l >/tmp/crt); cat /tmp/crt - | crontab'
done

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"