[12896] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 306 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 30 01:30:27 1999

Date: Thu, 29 Jul 1999 22:10:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 29 Jul 1999     Volume: 9 Number: 306

Today's topics:
    Re: Possible to Change Password for Services? <xrxoxtxhxdx@xrxoxtxhx.xnxextx>
        Printing lines BTW two strings in file (NOT!) <jhagen@blarg.net>
    Re: Printing lines BTW two strings in file (NOT!) <cmd@maths.uq.edu.au>
    Re: Printing lines BTW two strings in file (NOT!) <uri@sysarch.com>
    Re: Printing lines BTW two strings in file (NOT!) <uri@sysarch.com>
    Re: Seeking good Perl Examples (Martien Verbruggen)
    Re: Sending HTML emails from perl script (Martien Verbruggen)
    Re: Split is coming Back False?!? (Tad McClellan)
    Re: system function broken - ActivePerl - build 517 or  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 29 Jul 1999 21:18:07 -0700
From: "Dave Roth" <xrxoxtxhxdx@xrxoxtxhx.xnxextx>
Subject: Re: Possible to Change Password for Services?
Message-Id: <dG9o3.60566$AU3.1563918@news2.giganews.com>

Sam Weatherhead wrote in message <7nq2og$2p55@enews2.newsguy.com>...
>Can perl change the underlying password that is being used for
>a service to logon with? If so, what module do you use?


This is from Script 1 in our white papger "A Networked Machine
Management System" on our web site:
  http://www.roth.net/conference/lisant/1999/

This subroutine takes three parameters (in order):
  service name, userid, password


use Win32;
use Win32::API;
use Win32::Service;
use Win32::Lanman;

sub ConfigService
{  
  my( $Service, $User, $Password ) = @_;
  my $OpenSCManager = new Win32::API( 'advapi32.dll', 'OpenSCManager', [ P,P,L ], L );
  my $OpenService = new Win32::API( 'advapi32.dll', 'OpenService', [ L,P,L ], L );
  my $CloseServiceHandle = new Win32::API( 'advapi32.dll', 'CloseServiceHandle', [ L ], I );
  my $SCHandle, $ServiceHandle;
  my $ServiceString, $UserString, $PasswordString;  my %ServiceStatus;
  my $UnicodeFiller = "";    
  print "Configuring the $Service service ...\n";

  $Result = Win32::Service::GetStatus( '', $Service, \%ServiceStatus );

  # Service status 1 == Service has stopped
  $Result = Win32::Service::StopService( '', $Service ) if( 1 != $ServiceStatus->{CurrentState} );
    # Convert the string to UNICODE if needed
  $UnicodeFiller = "\x00" if( Win32::API::IsUnicode() );
  ( $ServiceString = $Service ) =~ s/(.)/$1$UnicodeFiller/g;  
  ( $UserString = $User ) =~ s/(.)/$1$UnicodeFiller/g;
  ( $PasswordString = $Password ) = s/(.)/$1$UnicodeFiller/g;
  # The flag 0x00F003F requests to open the service manager with full access
  if( $SCHandle = $OpenSCManager->Call( 0, 0, 0x000F003F ) )  
  {
    # The flag 0xC0000000 requests GENERIC_READ and GENERIC_WRITE
    if( $ServiceHandle = $OpenService->Call( $SCHandle, $ServiceString, 0xC0000000 ) )    
    { 
        my $ChangeServiceConfig = new Win32::API( 'advapi32.dll', 'ChangeServiceConfig', [ L,L,L,L,P,P,P,P,P,P,P ], I );
        
        # The 0x00000010 flag represents that the servic
e will logon as a user account
        # AND it will create it's own process (not share process space with
other services)
        # The 0xFFFFFFFF flag represents no change to this attribute.
        # The 0x00000002 flag represents the service is to auto start
        my $Result = $ChangeServiceConfig->Call( $ServiceHandle,
                                                 0x00000010,
                                                 0x00000002,
                                                 0xFFFFFFFF,
                                                 0,
                                                 0,
                                                 0,
                                                 0,
                                                 $UserString,
                                                 $PasswordString,
                                                 0 );        if( $Result )
        {
            print "Granting the $User account the privilege to logon as a
service\n";

            # Grant the service account with the privilege to logon as a
service...
            $Result = Win32::Lanman::GrantPrivilegeToAccount( '',
'SeServiceLogonRight', [$User] );
            if( ! $Result )
            {
                print "  Could not grant the privilege: ";
                print Win32::FormatMessage( Win32::Lanman::GetLastError() );
            }
        }
        else
        {
            print "  Could not modify the '$Service' service: ";
            print Win32::FormatMessage( Win32::GetLastError() );
        }
        $CloseServiceHandle->Call( $ServiceHandle );
      }
      else
      {
        print "Could not open the '$Service' service: ";
        print Win32::FormatMessage( Win32::GetLastError() );
    }
    $CloseServiceHandle->Call( $SCHandle );
  }
  else
  {
    print "  Could not open the service manager: ";
    print Win32::FormatMessage( Win32::GetLastError() );
  }
  Win32::Service::StartService( '', $Service );
}

--
=================================================================
Dave Roth                                ...glittering prizes and
Roth Consulting                      endless compromises, shatter
<rothd at roth dot net>                 the illusion of integrity
http://www.roth.net
Win32, Perl, C++, ODBC, Training

Our latest Perl book is now available:
"Win32 Perl Programming: The Standard Extensions"
http://www.roth.net/books/extensions/






------------------------------

Date: Thu, 29 Jul 1999 20:28:18 +0000
From: John Hagen <jhagen@blarg.net>
Subject: Printing lines BTW two strings in file (NOT!)
Message-Id: <37A0B962.CC6B92F0@blarg.net>

Good evening,

I have a perl script that does not print lines between two strings in  a file,
as I expected it would. In fact, it does not print anything at all.

My intent is to convert this into a script that uses splice to kill everything
in the list that holds lines from my filehandle except the numerical lines
between "BALANCING CONDITIONS" and the first line of stars in the block
enclosing "THIS BLOCK ENDS DATA". 

But first I wanted to test it by just printing out the lines that would be
skipped over by the inner while loop that I will use to determine those offsets,
and it failed.

I decided on an explicit method of referencing the lines in @eks_file because I
need the offsets into the file to use with splice after this script undergoes
more development.

Please take a look at my script and data. How is my script broken?

And, is there a better way to do this? Could I do this better with a multiline
match and grep? If so, how?

john hagen ~ jhagen@blarg.net
=============================

<perl script>

#! /usr/bin/perl
 
 open(EKS_FILE, $ARGV[0]) || die "Sorry, cannot open input file $ARGV[0]";
 
 @eks_file=<EKS_FILE>;
 
 foreach $i ( 0 .. $#eks_file ) {
     
     if ( $eks_file[$i] =~ /BALANCING CONDITIONS/ ) {
         
         while ( $eks_file[$i] !~ /\*\*\*\*/ ) {
 
             print "++> $eks_file[$i]";
 
         }
         
     }
 
 }
 
 close(EKS_FILE);
 
 
 <eks_file>
 
         
 ***** BALANCING CONDITIONS *****       
  12722X    322500  .205  2.000   -32044    -48066
  12534X    768093  .098  1.679   -23456    -35712
  12334X    867091  .105  1.450   -23456    -27768
  12638X    768093  .098  0.898   -13472    -32739
 1             ***********************
               * THIS BLOCK ENDS DATA*
               ***********************
 ***** BALANCING CONDITIONS *****       
  22722X    022500  .205  2.000   -02099    -98000
  22509X    708090  .098  2.079   -20950    -05722
  22009X    807092  .205  2.950   -20950    -27708
  22008X    708090  .098  0.898   -20972    -02709
 1             ***********************
               * THIS BLOCK ENDS DATA*
               ***********************


------------------------------

Date: Fri, 30 Jul 1999 14:31:49 +1000
From: chris dawson <cmd@maths.uq.edu.au>
To: John Hagen <jhagen@blarg.net>
Subject: Re: Printing lines BTW two strings in file (NOT!)
Message-Id: <37A12AB5.D3D03957@maths.uq.edu.au>

John Hagen wrote:

> <perl script>
> 
> #! /usr/bin/perl
> 
>  open(EKS_FILE, $ARGV[0]) || die "Sorry, cannot open input file $ARGV[0]";
> 
>  @eks_file=<EKS_FILE>;

Suppose you were to put 
	print $eks_file[0], "\n";
in here. (idiots guide to debugging tip #1)

I was under the impression that <EKS_FILE> returned the next line, not
the whole file.

I would do something like this

while ($line=<EKS_FILE>) {
	push @eks_file, $line;
}

And there are better ways to match multiple occurences of a character
than 
          $eks_file[$i] !~ /\*\*\*\*/ )

Chris


------------------------------

Date: 30 Jul 1999 00:18:50 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Printing lines BTW two strings in file (NOT!)
Message-Id: <x7u2qmojmd.fsf@home.sysarch.com>

>>>>> "JH" == John Hagen <jhagen@blarg.net> writes:

  JH> I have a perl script that does not print lines between two strings
  JH> in a file, as I expected it would. In fact, it does not print
  JH> anything at all.

read about the range operator .. in scalar context. this is well documented
in all the usual places.

  JH>  @eks_file=<EKS_FILE>;
 
  JH>  foreach $i ( 0 .. $#eks_file ) {

that is better done as:

	@eks_file = <EKS_FILE> ;
	foreach $line ( @eks_file ) {

or

	while( $line = <EKS_FILE> ) {

uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


------------------------------

Date: 30 Jul 1999 00:33:14 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Printing lines BTW two strings in file (NOT!)
Message-Id: <x7n1weoiyd.fsf@home.sysarch.com>

>>>>> "cd" == chris dawson <cmd@maths.uq.edu.au> writes:

  cd> John Hagen wrote:
  >> 
  >> @eks_file=<EKS_FILE>;

  cd> I was under the impression that <EKS_FILE> returned the next line, not
  cd> the whole file.

well you are under a wrong impression. ever heard about list vs. scalar
context?

  cd> I would do something like this

  cd> while ($line=<EKS_FILE>) {
  cd> 	push @eks_file, $line;
  cd> }

why do that, when his code actually did that in one line? so you are
attempting to correct a correct statement.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


------------------------------

Date: Fri, 30 Jul 1999 03:31:31 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Seeking good Perl Examples
Message-Id: <n09o3.110$g91.7238@nsw.nnrp.telstra.net>

In article <7npcvt$fam$1@news.ml.com>,
	"James Nedham" <James_Nedham@ml.com> writes:
> I am a newbie seeking good Perl examples, not CGI scripts.

Perl comes with lots of examples. The modules are good examples. The
documentation pages are good examples. The directories are good
examples. The Makefile is a good example. The word perl is a good
example. The names of the authors are good examples. Chameleons are
good examples.

An example of what?

>                                                             I am interested
> in scripts which look for certain processes to be running which notify me
> when they ahve died.

You could run something in a loop (while(){}) that uses an operating
specific tool to query the status of processes. Depends on your OS.

You could fork and exec the processes yourself, and watch for signals
coming back, or look at the process group (if you are on a OS that
supports this stuff)

I can't be more specific than that, because you aren't.

>                       Also I want to look at perl scripts that monitor log
> files and notify me when there are certain errors

tail -f the log file, and read that output in a perl program, checking
for the lines that you want to check for. You could also read:

# man perlfaq5
=head2 How do I do a C<tail -f> in perl?
[snip]
     How do I do a tail -f in perl?
[snip]

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | 
Commercial Dynamics Pty. Ltd.       | What's another word for Thesaurus?
NSW, Australia                      | 


------------------------------

Date: Fri, 30 Jul 1999 04:20:41 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Sending HTML emails from perl script
Message-Id: <tK9o3.125$g91.7238@nsw.nnrp.telstra.net>

In article <7nq1d2$ruk$1@nnrp1.deja.com>,
	jedaustin1999@my-deja.com writes:

> wrote:
>> I have a script which returns the contents of a
> script.  It is difficult to

Oh Puhleeze. If you wrap quoted stuff, do it correctly. Complain to
dejanews, or get a real news reader.

> Are imbedding the headers needed in the email to
> do this?

What? imbedding?

> IE: the Content-Type line below
> open (MAIL,"|/usr/sbin/sendmail $auditoremail\n");

Do not even call sendmail that way. It's dangerous. Unless you can be
100% certain of what is in that variable, don't even think about using
this. And what is that newline doing there?

Ask questions about sendmail in comp.mail.sendmail.
Ask questions about mime in comp.mail.mime.

>         print MAIL "MIME-Version: 1.0\n";
>         print MAIL "Content-Type: text/html\n";

Use here-doc syntax for this sort of thing.

# perldoc perldata

Even better: use a few of the standard modules to do this all.
MIME::Lite and Mail::Sendmail should be good starters. If you insist
on writing your own stuff, at least make sure that you knwo what
you're doing.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | I took an IQ test and the results were
Commercial Dynamics Pty. Ltd.       | negative.
NSW, Australia                      | 


------------------------------

Date: Thu, 29 Jul 1999 19:03:14 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Split is coming Back False?!?
Message-Id: <ijmqn7.hfr.ln@magna.metronet.com>

Mesarchm (mesarchm@aol.com) wrote:

: For some reason my split function is not updating.


   You haven't shown us any split() function.

   What on earth are you speaking of?


: {splitit($line) || print ERROR "$!\n";}


   If you want to know why splitit() isn't working, you are going
   to have to show us the code for it.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 29 Jul 1999 23:02:52 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: system function broken - ActivePerl - build 517 or 518
Message-Id: <37A115DC.9A61F09C@rochester.rr.com>

> ...

> Request for confirmation of bug in build 517 or 518 of ActivePerl for

> Win32:
>
> Applications fail to launch properly from a system function call under
> build 518. For example, the following simple program, which worked in
> build 516, is broken under 518.
>
> use diagnostics;
> use strict;
> print system 'CALC.EXE';
> print $!;
>
> Under 516, this launches the Nindows calculator application (if its on
> the path) but under 518, no calculator appears on the screen. (517 was
> not tested.)
>

 ...
I verify the behavior you see under 518 with Windows 95.  I also note that:

 ...
print system 'start calc.exe';
 ...

works fine.  I have no idea why the problem occurs.



------------------------------

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 306
*************************************


home help back first fref pref prev next nref lref last post