Operating System - HP-UX
1853530 Members
1983 Online
104088 Solutions
New Discussion

Re: crontab -e options....

 
SOLVED
Go to solution
someone_4
Honored Contributor

crontab -e options....

Hey everyone
I am trying to fix a cron job to redirect std out to dev null as adviced on another post.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x5ad89200caded5118ff40090279cd0f9,00.html

Now I have this cron job in about 40 servers. Is there a way I can edit/add/delete one cron job though a remote shell or another way so I dont have to log in and fix everyone by hand?

Thanks,
Richard
6 REPLIES 6
Thierry Poels_1
Honored Contributor
Solution

Re: crontab -e options....

hi,

sounds tricky, you will have to be very sure no-one else is editing a crontab on anyone of the servers.
You could try to remsh the following (I did not test/try this, that's up to you ;) :

crontab -l > /tmp/oldcron
ed /tmp/oldcron << [EOT]
,g;yourscriptname;s;$; > /dev/null 2>&1
w /tmp/newcron
q
[EOT]
crontab /tmp/newcron


The $ probably has to be escaped (\$), not sure yet : not really awake yet ;)

good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
G. Vrijhoeven
Honored Contributor

Re: crontab -e options....

Hi Richard,

it is possible:

crontab -l >crontab.org (to get cuttent crontab)
cat new_cron_lines >>crontab.org (appends lines)
# crontab corntab.org (loads new crontab)

Put this in a SD kit (configure script), or ftp to all servers and run this script with remsh.

Gideon
Sanjay_6
Honored Contributor

Re: crontab -e options....

Hi Richard,

I think you can use rsh or remsh to do this job. But then you have to modify the .rhosts file on all the servers. I would have suggested the format too, but won;t be able to do so now as i'm at home and can't connect to my server.

Hope this helps.

Regds
Roger Baptiste
Honored Contributor

Re: crontab -e options....

Hi Richard,

Since this is a root crontab, i guess you would be having full control over it, so should have the flexibility on when to change it.

On one Base system, edit, modify and implement the crontab script.
(eg:#login as root
# crontab -l >/tmp/rootcron.old
# cp /tmp/rootcron.old /tmp/rootcron
#vi rootcron (make changes)
#crontab /tmp/rootcron (implement it)
#make sure it is fine
)

Now, you can do the same on remaining systems remotely, only if you already have the .rhosts set up!
Otherwise, you would still need to login to
each of those boxes and set the .rhosts file!,
which is as good as logging into the system
and running the crontab commands ;-)

I think it is good to set up some mechanism
(.rhosts, or ssh keys ) between systems to
make transfer of files or running of remote
commands easier. This is especially needed when dealing with many systems in a site.
So, probably this is the right time to do it.

If you are not comfortable in opening remsh ports, setup secureshell.

-raj

Take it easy.
Darrell Allen
Honored Contributor

Re: crontab -e options....

Hi Richard,

May I suggest that the first thing your remsh does is to copy the root crontab to a safe location on each server.

If you are simply adding the same entry to each server I'd write a script that:
cd /var/spool/cron
cp -p crontabs/root root.`date`
crontab -l >root.new
echo "new crontab entry" >>root.new
crontab root.new

Then I'd create a file containing the hostnames of each of the other servers (one server per line).
Then I'd do:
for host in `cat list.of.hosts.file`
do
rcp script#1 $host:/var/tmp
remsh $host /var/tmp/script#1
done

Test this on one server before running on all. You may have to play with the permissions. As others have said, you need to have .rhosts configured for root on each server.

One word of caution concerning all systems having .rhosts set up for root. If the system that is allowed to remsh (no password) to the rest of the servers is compromised, all your servers are compromised. In my opinion, root login should be limited to the console and definitely root rlogin without a password should not be used.

My 2 cents.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Bernie Vande Griend
Respected Contributor

Re: crontab -e options....

You really have 2 separate issues here:
1) automating the editing of root's cron.
2) automating a change that must be done on multiple servers.

For #1: This is what I do:
crontab -l | grep -v "something unique in the cronjob I want to change/add" > /tmp/cron.root
NOTE: This means I really don't need to worry in the cron entry existed before or not, I can now add the entry I want.
echo "* * * * /opt/something/runit >/dev/null 2>&1" >> /tmp/cron.root
crontab cron.root

I'd put the above entries in a little script.

Now for #2: You can use rsh, SSH, expect, or some 3rd party software distribution tool. Another option would be to make a depot out of this and use an Ignite server to distibute it.
My choice, use ssh, first use scp to place the little script in /tmp on each server and then ssh root@servername /tmp/myscript to execute it. If you have that many servers to administrater its worth the effort to have ssh setup this way to make changes on your servers. Just make sure to protect the keys and limit the locations where it can be run from. This is also a handy way to change root passwords.
Good luck
Ye who thinks he has a lot to say, probably shouldn't.