Hi Guys,
so, getting it to the cmd line wasn't the problem, it was the interpretation by Perl eg
Puppet out: Debug: Exec[line_remove](provider=posix): Executing '/usr/bin/perl -w +-ni -e 'my $qs = quotemeta('ssh-rsa AAAA/BBBB/knMQ== user@host.f.q.d. +n'); print unless /^$qs$/ ' '/root/user/b1.bak'' Debug: Executing: '/usr/bin/perl -w -ni -e 'my $qs = quotemeta('ssh-rs +a AAAA/BBBB/knMQ== user@host.f.q.d.n'); print unless /^$qs$/ ' '/roo +t/user/b1.bak'' Notice: /Stage[main]/Main/Line[ssh_key]/Exec[line_remove]/returns: Unq +uoted string "ssh" may clash with future reserved word at -e line 1. Notice: /Stage[main]/Main/Line[ssh_key]/Exec[line_remove]/returns: syn +tax error at -e line 1, at EOF Notice: /Stage[main]/Main/Line[ssh_key]/Exec[line_remove]/returns: Exe +cution of -e aborted due to compilation errors. ## Same errors as direct at the cmd line # /usr/bin/perl -w -ni -e 'my $qs = quotemeta('ssh-rsa AAAA/BBBB/knMQ= += user@host.f.q.d.n'); print unless /^$qs$/ ' '/root/user/b1.bak' Unquoted string "ssh" may clash with future reserved word at -e line 1 +. syntax error at -e line 1, at EOF Execution of -e aborted due to compilation errors. # Try swap outer quotes '-> " # /usr/bin/perl -w -ni -e "my $qs = quotemeta('ssh-rsa AAAA/BBBB/knMQ= += user@host.f.q.d.n'); print unless /^$qs$/ " '/root/user/b1.bak' syntax error at -e line 1, near "my =" Execution of -e aborted due to compilation errors. # Try "" around quotemeta string # /usr/bin/perl -w -ni -e 'my $qs = quotemeta("ssh-rsa AAAA/BBBB/knMQ= += user@host.f.q.d.n"); print unless /^$qs$/ ' '/root/user/b1.bak' Possible unintended interpolation of @host in string at -e line 1. Name "main::host" used only once: possible typo at -e line 1.

However, using the post by gam3 here https://www.perlmonks.org/?node_id=438860 ('general soln'), it seemed to work
# Direct cli # perl -w -ni -e 'my $str = sprintf( qq(%s), q(ssh-rsa AAAA/BBBB/knMQ= += user@host.f.q.d.n) ); print $_ unless $_ =~ /$str/ ' /root/user/b1 +.bak # From within puppet command => "/usr/bin/perl -w -ni -e 'my \$str = sprintf( qq(%s), q($li +ne) ); print \$_ unless \$_ =~ /\$str/ ' '${file}'",

But a full ssh key has a '+' char as well, and that fails to match :(
# cat b1.bak ssh-rsa CCCC/DDDD/knMQ== user@host2.f.q.d.n ssh-rsa AAAA/BBBB/kPW+Yi9yZ7Kh0mL/knMQ== user@host.f.q.d.n # perl -w -n -e 'my $str = sprintf( qq(%s), q(ssh-rsa AAAA/BBBB/kPW+Y +i9yZ7Kh0mL/knMQ== user@host.f.q.d.n) ); print $_ unless $_ =~ /$str/ +' /root/user/b1.bak ssh-rsa CCCC/DDDD/knMQ== user@host2.f.q.d.n ssh-rsa AAAA/BBBB/kPW+Yi9yZ7Kh0mL/knMQ== user@host.f.q.d.n

So close ... damn it ... looks like I DO need to get quotemeta() working...
An ideas?

Cheers
Chris

BTW, when I write the post for perlmonks, it uses all the whitespace, but when I actually commit the post, it crams all code stuff to one side; why ?

In reply to Re: One liner: remove ssh keys with quotemeta by Anonymous Monk
in thread One liner: remove ssh keys with quotemeta by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.