in reply to passwords with special characters are trying to kill me... no seriously!

The problem is your incorrect use of \b in your regex. If you want to ensure a full match use string boundaries not word boundaries:

$s = 'fred';; print 'fred' =~ m[\b\Q$s\E\b] ? 'matched' : 'no match';; matched $s = '$fred';; print '$fred' =~ m[\b\Q$s\E\b] ? 'matched' : 'no match';; no match $s = '$fred';; print '$fred' =~ m[^\Q$s\E$] ? 'matched' : 'no match';; matched

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: passwords with special characters are trying to kill me... no seriously!
  • Download Code

Replies are listed 'Best First'.
Re^2: passwords with special characters are trying to kill me... no seriously!
by calmthestorm (Acolyte) on Feb 04, 2011 at 01:10 UTC
    Hmm, well it seems the passwords match now but it is still failing to set the password on the remote host using
    my $set_password = '/usr/bin/ssh ' . $targethost . " \"echo \Q$new_pas +sword\E | /usr/bin/passwd --stdin $username\""; system($set_password);
      it is still failing to set the password on the remote host using

      Sorry, but that is an entirely different problem and one well outside my field of experience.

      One thing that stands out though. Are you sure that /usr/bin/passwd will accept input from a pipe?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Yep, I have been running this script for a few months and it works great as long as the password doesnt have a special character like "$" in it.

        From the passwd manpage:

               --stdin
                      This  option is used to indicate that passwd should read the new pass-
                      word from standard input, which can be a pipe.
        
        Yep, it works like a charm, as long as the password does not contain any special characters.
      Possibly try using the quotemeta function which backslashes all non-"word" characters. This might work for you:
      my $set_password = qq(/usr/bin/ssh $targethost "echo ') . quotemeta($new_password) . qq(' | /usr/bin/passwd --stdin $username"); system($set_password);