Sorry, that delete_lines promise should have read

delete_lines:
  ".*$(fields[2])";

-----Original Message-----
From: help-cfengine-boun...@cfengine.org
[mailto:help-cfengine-boun...@cfengine.org] On Behalf Of Justin Lloyd
Sent: Monday, March 01, 2010 11:50 AM
To: Help-cfengine
Subject: RE: Editing known_hosts files

No responses? Ok, let me restate the problem more simply.

Given a file whose lines have three space-delimited fields, and given a
string variable that contains a similar line, how do I replace the
entire line in the file whose third field matches the third field in the
string with that variable? If there is no matching line, just insert the
string as a new line.

So if I have the file /tmp/test and the variable $(line) containing "a b
6" (not hard-coded but rather obtained from another host using
remotescalar()):

# cat /tmp/test
1 2 3
4 5 6
7 8 9
# cf-agent -Kf ./test.cf
# cat /tmp/test
1 2 3
a b 6
7 8 9
#

splitstring() returns an slist but you can't index into an slist to
match the ends of the lines, so the following does not work (but it or
something like it would be nice):

vars:

   "line" string => remotescalar(...);
  "fields" slist => splitstring("line", " ", 3);

delete_lines:

  ".*$(line[2])";

insert_lines:

  "$(line)";

Thoughts?

Thanks,
Justin

-----Original Message-----
From: help-cfengine-boun...@cfengine.org
[mailto:help-cfengine-boun...@cfengine.org] On Behalf Of Justin Lloyd
Sent: Friday, February 26, 2010 6:22 PM
To: Help-cfengine
Subject: Editing known_hosts files

Ok, I'm thoroughly stumped here. I had something from testing several
months ago that I thought was doing the right thing, but now I don't
think it was.

I want to insert into ~root/.ssh/known_hosts on certain hosts the root
public ssh key from a trusted root host. But the trickier part is to
delete any lines from the known_hosts file that match the beginning and
end of the new key to be added without affecting any other lines. For
example, say I have

$(trustedhostkey) = "ssh-dss blahblahblahblah r...@trustedhost"

and in the local ~root/.ssh/known_hosts file:

ssh-dss someoldkeytexthere r...@trustedhost
ssh-dss someotherkeytextab r...@anotherhost

I just want to replace the first line with $(trustedhostkey) since the
whole line doesn't match the new key but it does match ssh-dss at the
beginning and r...@trustedhost at the end. (If the right key is already
in the file, then it can be left alone.)

Before I had something like

vars:

    "key" string => remotescalar("root_key", "trustedhost", "yes"); #
yes = encryption
    "key_fields" slist => splitstring("$(key)", " ", 3)

delete_lines:

    "$(key_fields[0]) .* $(key_fields[2])";

insert_lines:

    "$(key)";

But now I've noticed that the indexing of an slist doesn't work. I've
been playing around with replace_patterns, trying to figure out how I
might use $(match.N) backrefs, but no success yet.

Any thoughts on how to do this?

Thanks,
Justin


This electronic communication and any attachments may contain
confidential and proprietary 
information of DigitalGlobe, Inc. If you are not the intended recipient,
or an agent or employee 
responsible for delivering this communication to the intended recipient,
or if you have received 
this communication in error, please do not print, copy, retransmit,
disseminate or 
otherwise use the information. Please indicate to the sender that you
have received this 
communication in error, and delete the copy you received. DigitalGlobe
reserves the 
right to monitor any electronic communication sent or received by its
employees, agents 
or representatives.

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to