<?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 PERL scripting problem in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-problem/m-p/2855064#M94489</link>
    <description>Hi,&lt;BR /&gt;I have the following PERL script attached in this message. It changes the encrypted passwd field in the /etc/passwd file  by reading the newly generated encrypted passwd from another file. Note also that I'm changing passwds not just for HP 11 machines, but also Solaris, AIX and Linux.&lt;BR /&gt;&lt;BR /&gt;This posting is similar in its description on the message which I posted about 1 week ago. At that time, I was looking for a AWK/SED script to solve the problem. &lt;BR /&gt;&lt;BR /&gt;However, I decided to give it a shot with PERL to change the passwd entry in /etc/passwd. &lt;BR /&gt;&lt;BR /&gt;But since I'm a newbie in PERL, my problem now is that I'm not sure how I could write the newly generated passwd into the /etc/passwd file. &lt;BR /&gt;&lt;BR /&gt;I do know how to use PERL's substitution operator to change the passwd with the new passwd, but I do not know how to write those changes in /etc/passwd file.&lt;BR /&gt;&lt;BR /&gt;Could someone help me out with my script attached?</description>
    <pubDate>Mon, 02 Dec 2002 01:30:04 GMT</pubDate>
    <dc:creator>Chern Jian Leaw</dc:creator>
    <dc:date>2002-12-02T01:30:04Z</dc:date>
    <item>
      <title>PERL scripting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-problem/m-p/2855064#M94489</link>
      <description>Hi,&lt;BR /&gt;I have the following PERL script attached in this message. It changes the encrypted passwd field in the /etc/passwd file  by reading the newly generated encrypted passwd from another file. Note also that I'm changing passwds not just for HP 11 machines, but also Solaris, AIX and Linux.&lt;BR /&gt;&lt;BR /&gt;This posting is similar in its description on the message which I posted about 1 week ago. At that time, I was looking for a AWK/SED script to solve the problem. &lt;BR /&gt;&lt;BR /&gt;However, I decided to give it a shot with PERL to change the passwd entry in /etc/passwd. &lt;BR /&gt;&lt;BR /&gt;But since I'm a newbie in PERL, my problem now is that I'm not sure how I could write the newly generated passwd into the /etc/passwd file. &lt;BR /&gt;&lt;BR /&gt;I do know how to use PERL's substitution operator to change the passwd with the new passwd, but I do not know how to write those changes in /etc/passwd file.&lt;BR /&gt;&lt;BR /&gt;Could someone help me out with my script attached?</description>
      <pubDate>Mon, 02 Dec 2002 01:30:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-problem/m-p/2855064#M94489</guid>
      <dc:creator>Chern Jian Leaw</dc:creator>
      <dc:date>2002-12-02T01:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: PERL scripting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-problem/m-p/2855065#M94490</link>
      <description>Strong advises:&lt;BR /&gt;&lt;BR /&gt;1. use strict&lt;BR /&gt;2. use warnings (for perl 5.005_03 and older use -w)&lt;BR /&gt;3. check all your open and close calls&lt;BR /&gt;4. use $^O for the OS name instead of unreliable external commands. I don't know the $^O for sunos and linux, so check that yourself)&lt;BR /&gt;5. use localtime and time instead of external date command&lt;BR /&gt;&lt;BR /&gt;Tips:&lt;BR /&gt;&lt;BR /&gt;1. use modules when writing cross OS scripts (when portability is an issue in general) instead of external commands&lt;BR /&gt;2. keep your lines within 80 characters wide&lt;BR /&gt;3. use lexicals wherever possible&lt;BR /&gt;4. initialize all your variables&lt;BR /&gt;&lt;BR /&gt;Rewritten script attached&lt;BR /&gt;&lt;BR /&gt;for your core question: unlink might be your clue</description>
      <pubDate>Mon, 02 Dec 2002 08:09:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-problem/m-p/2855065#M94490</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2002-12-02T08:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: PERL scripting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-problem/m-p/2855066#M94491</link>
      <description>Personally, I would take the safe method: &lt;BR /&gt;&lt;BR /&gt;- open passwd for reading&lt;BR /&gt;- open a NEW file for writing&lt;BR /&gt;- save the old passwd file&lt;BR /&gt;- move the old passwd out of the way&lt;BR /&gt;- move the new one into place&lt;BR /&gt;&lt;BR /&gt;This way you end up with a backup in case you have some problem (famous last word - "This has gotta work"). &lt;BR /&gt;&lt;BR /&gt;I'd especially recommend something like for the passwd file.   You'll be scrambling if your code has a bug. &lt;BR /&gt;&lt;BR /&gt;print "Filename";&lt;BR /&gt;$name = &amp;lt;&amp;gt;; &lt;BR /&gt;$outfile = "newfile";&lt;BR /&gt;&lt;BR /&gt;chomp $name;&lt;BR /&gt;&lt;BR /&gt;open(HANDLE, "&amp;lt;$name");&lt;BR /&gt;open(OUTFILE "&amp;gt;$outfile");&lt;BR /&gt;while (&lt;HANDLE&gt;)&lt;BR /&gt;{&lt;BR /&gt;        # do stuff&lt;BR /&gt;        print OUTFILE;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;close (HANDLE);&lt;BR /&gt;close (OUTFILE);&lt;BR /&gt;&lt;BR /&gt;mv $name $name.save&lt;BR /&gt;mv $outfile $name&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/HANDLE&gt;</description>
      <pubDate>Mon, 02 Dec 2002 14:42:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-problem/m-p/2855066#M94491</guid>
      <dc:creator>Rick Beldin</dc:creator>
      <dc:date>2002-12-02T14:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: PERL scripting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-problem/m-p/2855067#M94492</link>
      <description>Rick, his script *does* make a backup, with a timestamp. Look at the start of the script.&lt;BR /&gt;&lt;BR /&gt;Only safety issue you could add is to launch pwck before moving the old one out of the way.</description>
      <pubDate>Mon, 02 Dec 2002 15:10:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-problem/m-p/2855067#M94492</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2002-12-02T15:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: PERL scripting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-problem/m-p/2855068#M94493</link>
      <description>Whoops.  Didn't see the attachment paperclip.</description>
      <pubDate>Mon, 02 Dec 2002 15:27:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-problem/m-p/2855068#M94493</guid>
      <dc:creator>Rick Beldin</dc:creator>
      <dc:date>2002-12-02T15:27:49Z</dc:date>
    </item>
  </channel>
</rss>

