in reply to One liner: remove ssh keys with quotemeta
However, using the post by gam3 here https://www.perlmonks.org/?node_id=438860 ('general soln'), it seemed to workPuppet 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.
But a full ssh key has a '+' char as well, and that fails to match :(# 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}'",
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 ?# 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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: One liner: remove ssh keys with quotemeta
by hippo (Archbishop) on Nov 29, 2019 at 09:30 UTC | |
by Anonymous Monk on Dec 02, 2019 at 21:43 UTC | |
|
Re^2: One liner: remove ssh keys with quotemeta
by jcb (Parson) on Nov 29, 2019 at 17:27 UTC |