<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: perl pie question in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-pie-question/m-p/5113079#M685889</link>
    <description>&lt;!--!*#--&gt;Hi Shabu:&lt;BR /&gt;&lt;BR /&gt;This is one way:&lt;BR /&gt;&lt;BR /&gt;# cat ./fixshadow&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my $user = shift or die "User Name expected";&lt;BR /&gt;my $hash = shift or die "New password (hash) expected";&lt;BR /&gt;local $^I   = '.old';&lt;BR /&gt;local @ARGV = '/etc/shadow';&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    my @a = split(/:/);&lt;BR /&gt;    if ($a[0] =~ /^$user$/) {&lt;BR /&gt;        $a[1] = $hash;&lt;BR /&gt;        $_    = join ':', @a;&lt;BR /&gt;    }&lt;BR /&gt;    print;&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;...run as:&lt;BR /&gt;&lt;BR /&gt;# HASH='$1$Ic8qfl8h$cqja.zFziPK.j3bWx4SAL0'&lt;BR /&gt;# ./fixshadow tomcat ${HASH}&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Mon, 09 Jun 2008 19:38:24 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2008-06-09T19:38:24Z</dc:date>
    <item>
      <title>perl pie question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-pie-question/m-p/5113077#M685887</link>
      <description>&lt;BR /&gt;I am struggling to get this substitution going.&lt;BR /&gt;&lt;BR /&gt;I am trying to replace the hash keys in /etc/shadow with new hash keys, but my hash keys has special characters $ and . and all that, I need to use 'perl -p -i -e'&lt;BR /&gt;&lt;BR /&gt;#  perl -p -i -e "s/tomcat:\S+?:/tomcat:$1$Ic8qfl8h$cqja.zFziPK.j3bWx4SAL0:/" /etc/shadow&lt;BR /&gt;&lt;BR /&gt;# tail -1 /etc/shadow&lt;BR /&gt;tomcat:.zFziPK.j3bWx4SAL0:0:99999:7:::&lt;BR /&gt;&lt;BR /&gt;If you notice it is ignoring from '$' upto 'a' in the string.&lt;BR /&gt;I also tried double quotes and single quotes and different combinations.&lt;BR /&gt;&lt;BR /&gt;# HASH='$1$Ic8qfl8h$cqja.zFziPK.j3bWx4SAL0'&lt;BR /&gt;# perl -p -i -e "s/tomcat:+?:/tomcat:${HASH}:/" /etc/shadow&lt;BR /&gt;# tail -1 /etc/shadow&lt;BR /&gt;tomcat:.zFziPK.j3bWx4SAL0:0:99999:7:::&lt;BR /&gt;&lt;BR /&gt;# perl -p -i -e 's/tomcat:\S+?:/tomcat:'${HASH}':/' /etc/shadow&lt;BR /&gt;# tail -1 /etc/shadow&lt;BR /&gt;tomcat:.zFziPK.j3bWx4SAL0:99999:7:::&lt;BR /&gt;&lt;BR /&gt;# perl -p -i -e 's/tomcat:\S+?:/tomcat:${HASH}:/' /etc/shadow&lt;BR /&gt;# tail -1 /etc/shadow&lt;BR /&gt;tomcat::99999:7:::&lt;BR /&gt;&lt;BR /&gt;What would be the right combination?&lt;BR /&gt;&lt;BR /&gt;I also tried 'ed' works great, but how do I use a variable with ed?&lt;BR /&gt;&lt;BR /&gt;# EDITOR=/bin/ed&lt;BR /&gt;# ed /etc/shadow&lt;BR /&gt;1380&lt;BR /&gt;,s/^tomcat:.*:99999:7:::/tomcat:$1$Ic8qfl8h$cqja.zFziPK.j3bWx4SAL0/&lt;BR /&gt;w&lt;BR /&gt;1403&lt;BR /&gt;q&lt;BR /&gt;&lt;BR /&gt;# tail -1 /etc/shadow&lt;BR /&gt;tomcat:$1$Ic8qfl8h$cqja.zFziPK.j3bWx4SAL0&lt;BR /&gt;&lt;BR /&gt;Please advise.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Shabu&lt;BR /&gt;</description>
      <pubDate>Mon, 09 Jun 2008 18:43:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-pie-question/m-p/5113077#M685887</guid>
      <dc:creator>Shabu Khan-2</dc:creator>
      <dc:date>2008-06-09T18:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: perl pie question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-pie-question/m-p/5113078#M685888</link>
      <description>&lt;BR /&gt;I can always backslash the $ and any special characters to get this working, but I am looking for a better solution - without mucking with the actual hash key.&lt;BR /&gt;&lt;BR /&gt;This would work but inelegant.&lt;BR /&gt;# HASH='\$1\$Ic8qfl8h\$cqja\.zFziPK\.j3bWx4SAL0'&lt;BR /&gt;# perl -p -i -e "s/tomcat:\S+?:/tomcat:${HASH}:/" /etc/shadow&lt;BR /&gt;# tail -1 /etc/shadow&lt;BR /&gt;tomcat:$1$Ic8qfl8h$cqja.zFziPK.j3bWx4SAL0:0:99999:7:::&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Shabu</description>
      <pubDate>Mon, 09 Jun 2008 19:34:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-pie-question/m-p/5113078#M685888</guid>
      <dc:creator>Shabu Khan-2</dc:creator>
      <dc:date>2008-06-09T19:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: perl pie question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-pie-question/m-p/5113079#M685889</link>
      <description>&lt;!--!*#--&gt;Hi Shabu:&lt;BR /&gt;&lt;BR /&gt;This is one way:&lt;BR /&gt;&lt;BR /&gt;# cat ./fixshadow&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my $user = shift or die "User Name expected";&lt;BR /&gt;my $hash = shift or die "New password (hash) expected";&lt;BR /&gt;local $^I   = '.old';&lt;BR /&gt;local @ARGV = '/etc/shadow';&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    my @a = split(/:/);&lt;BR /&gt;    if ($a[0] =~ /^$user$/) {&lt;BR /&gt;        $a[1] = $hash;&lt;BR /&gt;        $_    = join ':', @a;&lt;BR /&gt;    }&lt;BR /&gt;    print;&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;...run as:&lt;BR /&gt;&lt;BR /&gt;# HASH='$1$Ic8qfl8h$cqja.zFziPK.j3bWx4SAL0'&lt;BR /&gt;# ./fixshadow tomcat ${HASH}&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 09 Jun 2008 19:38:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-pie-question/m-p/5113079#M685889</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-06-09T19:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: perl pie question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-pie-question/m-p/5113080#M685890</link>
      <description>$ cat &amp;gt; shadow&lt;BR /&gt;tomcat:.zFziPK.j3bWx4SAL0:0:99999:7:::&lt;BR /&gt;$ export HASH='$1$Ic8qfl8h$cqja.zFziPK.j3bWx4SAL0'&lt;BR /&gt;$ perl -p -e 's/tomcat:[^:]+:/tomcat:$ENV{HASH}:/' shadow&lt;BR /&gt;tomcat:$1$Ic8qfl8h$cqja.zFziPK.j3bWx4SAL0:0:99999:7:::&lt;BR /&gt;&lt;BR /&gt;or &lt;BR /&gt;$ perl -p -e 's/^(tomcat:)[^:]+:/$1$ENV{HASH}:/' shadow&lt;BR /&gt;tomcat:$1$Ic8qfl8h$cqja.zFziPK.j3bWx4SAL0:0:99999:7:::&lt;BR /&gt;&lt;BR /&gt;- NO command line shell substitutions.&lt;BR /&gt;- Pick up the shell variable from the %ENV associative array.&lt;BR /&gt;- Make the replace target be:  [^:]+ &lt;BR /&gt;That is a sequence of 1 or more non-colon characters.&lt;BR /&gt;- you add the -i and real file.&lt;BR /&gt;&lt;BR /&gt;Enjoy,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Tue, 10 Jun 2008 03:04:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-pie-question/m-p/5113080#M685890</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-06-10T03:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: perl pie question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-pie-question/m-p/5113081#M685891</link>
      <description>Closing this out</description>
      <pubDate>Tue, 10 Jun 2008 17:14:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-pie-question/m-p/5113081#M685891</guid>
      <dc:creator>Shabu Khan-2</dc:creator>
      <dc:date>2008-06-10T17:14:34Z</dc:date>
    </item>
  </channel>
</rss>

