<?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 help needed in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-help-needed/m-p/2869458#M98052</link>
    <description>Hi,&lt;BR /&gt;I have a PERL script attached in this message which reads the contents of several input files having the format:&lt;BR /&gt;&lt;BR /&gt;addtogroup:ken_lee:grpA:rick_hyun:ken_lee&lt;BR /&gt;These input files containing the above formatted data all begin with the name "spool" i.e:&lt;BR /&gt;spool.groupnameADD.userToAdd.group.PID&lt;BR /&gt;e.g:&lt;BR /&gt;spool.grpAADD.rick_hyun.grpA.12434&lt;BR /&gt;&lt;BR /&gt;The script attached basically takes the output above, which is generated from another PERL script. It then tokenizes ken_lee, grpA and rick_hyun and passes them into &lt;BR /&gt;another script called edgrp.&lt;BR /&gt;&lt;BR /&gt;The script edgrp takes the tokenized elements and adds them into the group grpA, where ken_lee is the group owner and rick_hyun is the person to be added in. The edgrp script then pushes these changes to the NIS group file to all of its maps.&lt;BR /&gt;edgrp script is invoked the following way:&lt;BR /&gt;# edgrp &lt;ADD&gt; &lt;USER&gt; &lt;GROUP&gt; &amp;lt; passwd_file&lt;BR /&gt;# edgrp &lt;DEL&gt; &lt;USER&gt; &lt;GROUP&gt; &amp;lt; passwd_file&lt;BR /&gt;passwd_file is the file containing the user-name of the group leader and its passwd of the format:&lt;BR /&gt;ken_lee&lt;BR /&gt;z768v!plQ&lt;BR /&gt; &lt;BR /&gt;However, there is an issue of concurrency with the script - If there is &amp;gt;1 person invoking this script, then the data to be added is not consistent, i.e. same person gets added into same group twice. &lt;BR /&gt;&lt;BR /&gt;The edgrp script by itself adds and deletes users from the NIS groups properly, when invoked with one the purpose of adding &lt;BR /&gt;or removing 1 user at a time. &lt;BR /&gt;&lt;BR /&gt;I was wondering if anyone could provide some guide on how I could implement some kind of "thread" or synchronization mechanism&lt;BR /&gt;in PERL which would provide some concurrency control over the script whenever the sub-routine add() or remove() is called? &lt;BR /&gt;Or perhaps some other modification to the script that would ensure concurrency? &lt;BR /&gt;&lt;BR /&gt;The subroutines add() and remove() calls the script edgrp with the proper parameters to perform the "real" work of adding or&lt;BR /&gt;deleting users from a NIS group.&lt;BR /&gt;&lt;BR /&gt;Could anyone kindly help me out? &lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;/GROUP&gt;&lt;/USER&gt;&lt;/DEL&gt;&lt;/GROUP&gt;&lt;/USER&gt;&lt;/ADD&gt;</description>
    <pubDate>Mon, 23 Dec 2002 15:54:38 GMT</pubDate>
    <dc:creator>Chern Jian Leaw</dc:creator>
    <dc:date>2002-12-23T15:54:38Z</dc:date>
    <item>
      <title>PERL scripting help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-help-needed/m-p/2869458#M98052</link>
      <description>Hi,&lt;BR /&gt;I have a PERL script attached in this message which reads the contents of several input files having the format:&lt;BR /&gt;&lt;BR /&gt;addtogroup:ken_lee:grpA:rick_hyun:ken_lee&lt;BR /&gt;These input files containing the above formatted data all begin with the name "spool" i.e:&lt;BR /&gt;spool.groupnameADD.userToAdd.group.PID&lt;BR /&gt;e.g:&lt;BR /&gt;spool.grpAADD.rick_hyun.grpA.12434&lt;BR /&gt;&lt;BR /&gt;The script attached basically takes the output above, which is generated from another PERL script. It then tokenizes ken_lee, grpA and rick_hyun and passes them into &lt;BR /&gt;another script called edgrp.&lt;BR /&gt;&lt;BR /&gt;The script edgrp takes the tokenized elements and adds them into the group grpA, where ken_lee is the group owner and rick_hyun is the person to be added in. The edgrp script then pushes these changes to the NIS group file to all of its maps.&lt;BR /&gt;edgrp script is invoked the following way:&lt;BR /&gt;# edgrp &lt;ADD&gt; &lt;USER&gt; &lt;GROUP&gt; &amp;lt; passwd_file&lt;BR /&gt;# edgrp &lt;DEL&gt; &lt;USER&gt; &lt;GROUP&gt; &amp;lt; passwd_file&lt;BR /&gt;passwd_file is the file containing the user-name of the group leader and its passwd of the format:&lt;BR /&gt;ken_lee&lt;BR /&gt;z768v!plQ&lt;BR /&gt; &lt;BR /&gt;However, there is an issue of concurrency with the script - If there is &amp;gt;1 person invoking this script, then the data to be added is not consistent, i.e. same person gets added into same group twice. &lt;BR /&gt;&lt;BR /&gt;The edgrp script by itself adds and deletes users from the NIS groups properly, when invoked with one the purpose of adding &lt;BR /&gt;or removing 1 user at a time. &lt;BR /&gt;&lt;BR /&gt;I was wondering if anyone could provide some guide on how I could implement some kind of "thread" or synchronization mechanism&lt;BR /&gt;in PERL which would provide some concurrency control over the script whenever the sub-routine add() or remove() is called? &lt;BR /&gt;Or perhaps some other modification to the script that would ensure concurrency? &lt;BR /&gt;&lt;BR /&gt;The subroutines add() and remove() calls the script edgrp with the proper parameters to perform the "real" work of adding or&lt;BR /&gt;deleting users from a NIS group.&lt;BR /&gt;&lt;BR /&gt;Could anyone kindly help me out? &lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;/GROUP&gt;&lt;/USER&gt;&lt;/DEL&gt;&lt;/GROUP&gt;&lt;/USER&gt;&lt;/ADD&gt;</description>
      <pubDate>Mon, 23 Dec 2002 15:54:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-help-needed/m-p/2869458#M98052</guid>
      <dc:creator>Chern Jian Leaw</dc:creator>
      <dc:date>2002-12-23T15:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: PERL scripting help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-help-needed/m-p/2869459#M98053</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;You could of course use a temporary lock file (e.g. /tmp/edgrp.lck). Let edgrp check for the lock file and only add() or remove() a user if the file doesn't exist;&lt;BR /&gt;&lt;BR /&gt;There are some articles over at the Perl Journal (&lt;A href="http://www.tpj.com)" target="_blank"&gt;www.tpj.com)&lt;/A&gt; that discuss resource locking. This article uses semaphores: &lt;A href="http://www.samag.com/documents/s=4075/sam1013019385270/sam0203i.htm" target="_blank"&gt;http://www.samag.com/documents/s=4075/sam1013019385270/sam0203i.htm&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;This one is especially about resource locking over networks: &lt;A href="http://www.samag.com/documents/s=7178/sam0206j/" target="_blank"&gt;http://www.samag.com/documents/s=7178/sam0206j/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Vincent</description>
      <pubDate>Mon, 23 Dec 2002 16:09:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-help-needed/m-p/2869459#M98053</guid>
      <dc:creator>Vincent Stedema</dc:creator>
      <dc:date>2002-12-23T16:09:24Z</dc:date>
    </item>
    <item>
      <title>Re: PERL scripting help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-help-needed/m-p/2869460#M98054</link>
      <description>Vincent,&lt;BR /&gt;&lt;BR /&gt;I was wondering if you could show me how I could implement the temporary lock file for this purpose? &lt;BR /&gt;&lt;BR /&gt;I'm rather a newbie in the area of concurrency access with PERL - would greatly appreciate it if you could provide some guidlines as to how I can implement the locking mechanism.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Tue, 24 Dec 2002 02:11:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-help-needed/m-p/2869460#M98054</guid>
      <dc:creator>Chern Jian Leaw</dc:creator>
      <dc:date>2002-12-24T02:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: PERL scripting help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-help-needed/m-p/2869461#M98055</link>
      <description>Create a subroutine, pidlock - this will check the LOCKFILE exists, and if it does, that the pid it contains is still running.  If it is, it returns 0.  If it isn't, the LOCKFILE is created and it returns 1:&lt;BR /&gt;&lt;BR /&gt;sub pidlock{&lt;BR /&gt;        my($LOCKFILE) = @_;&lt;BR /&gt;        if(-s "$LOCKFILE"){&lt;BR /&gt;                die "Cannot open lock file $LOCKFILE, $!\n" unless open LOCK, "$LOCKFILE";&lt;BR /&gt;                my $pid=&lt;LOCK&gt;;&lt;BR /&gt;                chomp $pid;&lt;BR /&gt;                if ( $pid =~ m#([\d]+)$# ) {&lt;BR /&gt;                 my $n=kill 0, $1;&lt;BR /&gt;                 return 0 if($n &amp;gt;0);&lt;BR /&gt;                }&lt;BR /&gt;                close LOCK;&lt;BR /&gt;                die "Cannot remove $LOCKFILE, $!\n" unless unlink("$LOCKFILE");&lt;BR /&gt;        }&lt;BR /&gt;        die "Cannot open lock file $LOCKFILE, $!\n" unless open LOCK, "&amp;gt;$LOCKFILE";&lt;BR /&gt;        print LOCK "$$\n";&lt;BR /&gt;        close LOCK;&lt;BR /&gt;        return 1;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Then early in your script, call:&lt;BR /&gt;&lt;BR /&gt;$LOCKFILE="/tmp/edgrp.lock";&lt;BR /&gt;die "edgrp already running\n" unless pidlock($LOCKFILE);&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin&lt;/LOCK&gt;</description>
      <pubDate>Tue, 24 Dec 2002 08:27:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-help-needed/m-p/2869461#M98055</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2002-12-24T08:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: PERL scripting help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-help-needed/m-p/2869462#M98056</link>
      <description>Robin,&lt;BR /&gt;what should the LOCKFILE contain? Will it contain the PID of the current process invoking the edgrp script to perform add() or delete()? &lt;BR /&gt;&lt;BR /&gt;Could you tell me where should I call the subroutine pidlock()? when should the lock be released?&lt;BR /&gt;&lt;BR /&gt;Sorry I'm rather a newbie to the area of resource locking and semaphores.&lt;BR /&gt;&lt;BR /&gt;Greatly appreciate it if you explain a little bit more.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 24 Dec 2002 10:15:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-help-needed/m-p/2869462#M98056</guid>
      <dc:creator>Chern Jian Leaw</dc:creator>
      <dc:date>2002-12-24T10:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: PERL scripting help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-help-needed/m-p/2869463#M98057</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Robin's subroutine checks whether a lock file ('/tmp/edgrp.lock') exists. If it does exist, it checks whether the process that created the lock file is still running. If this is not the case, or when there is no lock file, edgrp can be executed. It writes its own PID to /tmp/edgrp.lock and returns a boolean true value.&lt;BR /&gt;&lt;BR /&gt;If the lock file exists and the process that created it is still running, it will do nothing and return a boolean false value.&lt;BR /&gt;&lt;BR /&gt;You would best incorporate this subroutine at the beginning of your script:&lt;BR /&gt;&lt;BR /&gt;my $lockfile = '/tmp/edgrp.lock';&lt;BR /&gt;foreach $i (@spoolList){&lt;BR /&gt;        print "\$i = $i \n";&lt;BR /&gt;        my @tokens = &amp;amp;tokenizeElements($i);&lt;BR /&gt;        $action = $tokens[0];&lt;BR /&gt;        $owner = $tokens[1];&lt;BR /&gt;        $grpName = $tokens[2];&lt;BR /&gt;        $user = $tokens[3];&lt;BR /&gt;&lt;BR /&gt;        print "\$action is $action \n";&lt;BR /&gt;        print "\$owner is $owner \n";&lt;BR /&gt;        print "\$grpName is $grpName \n";&lt;BR /&gt;        print "\$user is $user \n";&lt;BR /&gt;&lt;BR /&gt;        die "Another instance of edgrp is already running" unless &amp;amp;pidlock($lockfile);&lt;BR /&gt;        &amp;amp;processReq($action, $owner, $grpName, $user);&lt;BR /&gt;        system("rm -rf $i");&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Vincent&lt;BR /&gt;</description>
      <pubDate>Tue, 24 Dec 2002 15:22:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-scripting-help-needed/m-p/2869463#M98057</guid>
      <dc:creator>Vincent Stedema</dc:creator>
      <dc:date>2002-12-24T15:22:42Z</dc:date>
    </item>
  </channel>
</rss>

