Kicking off multiple processes at once instead of waiting....

Discussion in 'Perl Misc' started by Simon, Jun 29, 2007.

  1. Simon

    Simon Guest

    Hi guys hope you can help.

    I have the following script which connects to remote machines and returns
    information about the values of certain registry keys.
    All is good, but the way the script runs is that it does this....
    Connects to first machine.......returns data
    Then connects to next machine....returns data
    Then the next
    Then the next and so on.

    What Id like to be able to do, because we have so many machines to process,
    is to do the following...

    Connect to, say 10 machines all at the same time, then return data back to
    the one main console (where I executed the script in the first place),
    instead of waiting for 1 machine to end, then move on to the next.

    Any help greatly appreciated. Here is the script.

    ================================================================= Script

    use Win32;
    use Win32::Registry;

    sub RunRegQuery {

    $p = 'Software\Network Associates\TVD\VirusScan Enterprise\CurrentVersion';
    Win32::RegOpenKeyEx(&HKEY_LOCAL_MACHINE,$p,&NULL,&
    KEY_QUERY_VALUE|&KEY_SET_VALUE,$hkey);
    Win32::RegQueryValueEx($hkey,"szVirDefVer",&NULL,$ type,$Definition);
    Win32::RegQueryValueEx($hkey,"szProductVer",&NULL, $type,$Product);
    Win32::RegQueryValueEx($hkey,"szEngineVer",&NULL,$ type,$Engine);

    print "$SystemName\n";
    print "$Definition\n";
    print "$Product\n";
    print "$Engine\n";
    print " \n";
    }

    ##########
    ## MAIN ##
    ##########

    open (Store, "< llsystems.txt") or die "can't open systems.txt: $!";
    foreach $line (<Store>)
    {
    chomp($line);
    $SystemName = $line;
    if ($SystemName =~ /^l/i) {
    system ("net use \\\\$SystemName\\ipc\$ "password"
    /user:$SystemName\\useraccount > NUL");
    sleep 3;
    RunRegQuery();
    system ("net use \\\\$SystemName\\ipc\$ /delete /y > 2NUL > NUL"); # Delete
    previous connection
    }
    else {
    print "not a valid system\n";
    }
    }
    close (Store);
    exit;

    =================================================================== End of
    script

    Output is as follows..

    C:\>script.pl
    Lcomputer1
    5060
    8.0.0.912
    5100
    Lcomputer2
    5060
    8.0.0.912
    5100
    Lcomputer3
    5060
    8.0.0.912
    5100

    etc etc

    Any help greatly appreciated guys, thank you.

    S
     
    Simon, Jun 29, 2007
    #1
    1. Advertisements

  2. Simon

    Guest

    "Simon" <> wrote in message-id: <zY_gi.458$>

    >
    > Hi guys hope you can help.
    >
    > I have the following script which connects to remote machines and returns
    > information about the values of certain registry keys.
    > All is good, but the way the script runs is that it does this....
    > Connects to first machine.......returns data
    > Then connects to next machine....returns data
    > Then the next
    > Then the next and so on.
    >
    > What Id like to be able to do, because we have so many machines to process,
    > is to do the following...
    >
    > Connect to, say 10 machines all at the same time, then return data back to
    > the one main console (where I executed the script in the first place),
    > instead of waiting for 1 machine to end, then move on to the next.
    >
    > Any help greatly appreciated. Here is the script.
    >
    > ================================================================= Script
    >
    > use Win32;
    > use Win32::Registry;
    >
    > sub RunRegQuery {
    >
    > $p = 'Software\Network Associates\TVD\VirusScan Enterprise\CurrentVersion';
    > Win32::RegOpenKeyEx(&HKEY_LOCAL_MACHINE,$p,&NULL,&
    > KEY_QUERY_VALUE|&KEY_SET_VALUE,$hkey);
    > Win32::RegQueryValueEx($hkey,"szVirDefVer",&NULL,$ type,$Definition);
    > Win32::RegQueryValueEx($hkey,"szProductVer",&NULL, $type,$Product);
    > Win32::RegQueryValueEx($hkey,"szEngineVer",&NULL,$ type,$Engine);
    >
    > print "$SystemName\n";
    > print "$Definition\n";
    > print "$Product\n";
    > print "$Engine\n";
    > print " \n";
    > }
    >
    > ##########
    > ## MAIN ##
    > ##########
    >
    > open (Store, "< llsystems.txt") or die "can't open systems.txt: $!";
    > foreach $line (<Store>)
    > {
    > chomp($line);
    > $SystemName = $line;
    > if ($SystemName =~ /^l/i) {
    > system ("net use \\\\$SystemName\\ipc\$ "password"
    > /user:$SystemName\\useraccount > NUL");
    > sleep 3;
    > RunRegQuery();
    > system ("net use \\\\$SystemName\\ipc\$ /delete /y > 2NUL > NUL"); # Delete
    > previous connection
    > }
    > else {
    > print "not a valid system\n";
    > }
    > }
    > close (Store);
    > exit;
    >
    > =================================================================== End of
    > script
    >
    > Output is as follows..
    >
    > C:\>script.pl
    > Lcomputer1
    > 5060
    > 8.0.0.912
    > 5100
    > Lcomputer2
    > 5060
    > 8.0.0.912
    > 5100
    > Lcomputer3
    > 5060
    > 8.0.0.912
    > 5100
    >
    > etc etc
    >
    > Any help greatly appreciated guys, thank you.
    >
    > S


    Just use Threads
     
    , Jun 29, 2007
    #2
    1. Advertisements

  3. Simon

    Simon Guest

    Hi QoS,

    Thanks for your input.

    Do you mean the module Threads?


    <> wrote in message news:qr%gi.5424$ss5.76@trndny03...
    >
    > "Simon" <> wrote in message-id:
    > <zY_gi.458$>
    >
    >>
    >> Hi guys hope you can help.
    >>
    >> I have the following script which connects to remote machines and returns
    >> information about the values of certain registry keys.
    >> All is good, but the way the script runs is that it does this....
    >> Connects to first machine.......returns data
    >> Then connects to next machine....returns data
    >> Then the next
    >> Then the next and so on.
    >>
    >> What Id like to be able to do, because we have so many machines to
    >> process,
    >> is to do the following...
    >>
    >> Connect to, say 10 machines all at the same time, then return data back
    >> to
    >> the one main console (where I executed the script in the first place),
    >> instead of waiting for 1 machine to end, then move on to the next.
    >>
    >> Any help greatly appreciated. Here is the script.
    >>
    >> ================================================================= Script
    >>
    >> use Win32;
    >> use Win32::Registry;
    >>
    >> sub RunRegQuery {
    >>
    >> $p = 'Software\Network Associates\TVD\VirusScan
    >> Enterprise\CurrentVersion';
    >> Win32::RegOpenKeyEx(&HKEY_LOCAL_MACHINE,$p,&NULL,&
    >> KEY_QUERY_VALUE|&KEY_SET_VALUE,$hkey);
    >> Win32::RegQueryValueEx($hkey,"szVirDefVer",&NULL,$ type,$Definition);
    >> Win32::RegQueryValueEx($hkey,"szProductVer",&NULL, $type,$Product);
    >> Win32::RegQueryValueEx($hkey,"szEngineVer",&NULL,$ type,$Engine);
    >>
    >> print "$SystemName\n";
    >> print "$Definition\n";
    >> print "$Product\n";
    >> print "$Engine\n";
    >> print " \n";
    >> }
    >>
    >> ##########
    >> ## MAIN ##
    >> ##########
    >>
    >> open (Store, "< llsystems.txt") or die "can't open systems.txt: $!";
    >> foreach $line (<Store>)
    >> {
    >> chomp($line);
    >> $SystemName = $line;
    >> if ($SystemName =~ /^l/i) {
    >> system ("net use \\\\$SystemName\\ipc\$ "password"
    >> /user:$SystemName\\useraccount > NUL");
    >> sleep 3;
    >> RunRegQuery();
    >> system ("net use \\\\$SystemName\\ipc\$ /delete /y > 2NUL > NUL"); #
    >> Delete
    >> previous connection
    >> }
    >> else {
    >> print "not a valid system\n";
    >> }
    >> }
    >> close (Store);
    >> exit;
    >>
    >> =================================================================== End
    >> of
    >> script
    >>
    >> Output is as follows..
    >>
    >> C:\>script.pl
    >> Lcomputer1
    >> 5060
    >> 8.0.0.912
    >> 5100
    >> Lcomputer2
    >> 5060
    >> 8.0.0.912
    >> 5100
    >> Lcomputer3
    >> 5060
    >> 8.0.0.912
    >> 5100
    >>
    >> etc etc
    >>
    >> Any help greatly appreciated guys, thank you.
    >>
    >> S

    >
    > Just use Threads
    >
     
    Simon, Jun 29, 2007
    #3
  4. Simon

    Joe Schaefer Guest

    "Simon" <> writes:

    > What Id like to be able to do, because we have so many machines to
    > process, is to do the following...
    >
    > Connect to, say 10 machines all at the same time, then return data
    > back to the one main console (where I executed the script in the first
    > place), instead of waiting for 1 machine to end, then move on to the
    > next.
    >
    > Any help greatly appreciated. Here is the script.
    >
    > ================================================================= Script
    >
    > use Win32;
    > use Win32::Registry;



    [...]

    > system ("net use \\\\$SystemName\\ipc\$ "password"
    > /user:$SystemName\\useraccount > NUL");
    > sleep 3;
    > RunRegQuery();
    > system ("net use \\\\$SystemName\\ipc\$ /delete /y > 2NUL > NUL"); # Delete
    > previous connection


    What you want to do sounds fine, but personally I don't think you're
    asking the right question. What you should be asking is "How do I get
    rid of these system() calls in my script?", because there's no way
    to parallelize your script without doing at least that.

    If I were you, I'd be looking over the Win32::Registry documentation
    for a way to directly connect to a remote registry. If you can figure
    out how to do that, you should be able to access the repository by
    calling a suitably modified version of

    RunRegQuery($SystemName);

    without ever needing to make those calls to system() and sleep().

    If it turns out *that* script isn't fast enough, at that point people
    will be able to give you advice on how to parallellize it like you
    have originally asked.

    --
    Joe Schaefer
     
    Joe Schaefer, Jun 29, 2007
    #4
  5. Simon

    Simon Guest

    Thanks Joe..much appreciated.

    I do know Joe how to connect to a remote registry.

    I spose what Im trying to do, but cant get myself on some really really
    simple examples, so i can play with them, are example scripts on how to fork
    a process.
    Ive looked at the perldoc but I find the doco not as clear as some good
    beginner fork examples so I can test them out on my systems, then gain
    confidence that way.

    Appreciate your help. :)

    "Joe Schaefer" <> wrote in message
    news:...
    > "Simon" <> writes:
    >
    >> What Id like to be able to do, because we have so many machines to
    >> process, is to do the following...
    >>
    >> Connect to, say 10 machines all at the same time, then return data
    >> back to the one main console (where I executed the script in the first
    >> place), instead of waiting for 1 machine to end, then move on to the
    >> next.
    >>
    >> Any help greatly appreciated. Here is the script.
    >>
    >> ================================================================= Script
    >>
    >> use Win32;
    >> use Win32::Registry;

    >
    >
    > [...]
    >
    >> system ("net use \\\\$SystemName\\ipc\$ "password"
    >> /user:$SystemName\\useraccount > NUL");
    >> sleep 3;
    >> RunRegQuery();
    >> system ("net use \\\\$SystemName\\ipc\$ /delete /y > 2NUL > NUL"); #
    >> Delete
    >> previous connection

    >
    > What you want to do sounds fine, but personally I don't think you're
    > asking the right question. What you should be asking is "How do I get
    > rid of these system() calls in my script?", because there's no way
    > to parallelize your script without doing at least that.
    >
    > If I were you, I'd be looking over the Win32::Registry documentation
    > for a way to directly connect to a remote registry. If you can figure
    > out how to do that, you should be able to access the repository by
    > calling a suitably modified version of
    >
    > RunRegQuery($SystemName);
    >
    > without ever needing to make those calls to system() and sleep().
    >
    > If it turns out *that* script isn't fast enough, at that point people
    > will be able to give you advice on how to parallellize it like you
    > have originally asked.
    >
    > --
    > Joe Schaefer
     
    Simon, Jun 29, 2007
    #5
  6. Simon

    Guest

    "Simon" <> wrote in message-id: <Dh5hi.933$>

    >
    > Hi QoS,
    >
    > Thanks for your input.
    >
    > Do you mean the module Threads?
    >
    >
    > <> wrote in message news:qr%gi.5424$ss5.76@trndny03...
    > >
    > > "Simon" <> wrote in message-id:
    > > <zY_gi.458$>
    > >
    > >>

    [snip]
    > >> Connect to, say 10 machines all at the same time, then return data back
    > >> to
    > >> the one main console (where I executed the script in the first place),
    > >> instead of waiting for 1 machine to end, then move on to the next.
    > >>
    > >> Any help greatly appreciated. Here is the script.
    > >>

    [snip]
    > >> Any help greatly appreciated guys, thank you.
    > >>
    > >> S

    > >
    > > Just use Threads
    > >


    Yeah have a look at:
    perldoc perlthrtut
    and
    perldoc Threads
    and
    perldoc Threads::Shared

    HtH

    J
     
    , Jun 29, 2007
    #6
  7. Simon

    Simon Guest

    Thanks QoS...appreciate it mate.

    <> wrote in message news:k29hi.11$4e5.4@trndny07...
    >
    > "Simon" <> wrote in message-id:
    > <Dh5hi.933$>
    >
    >>
    >> Hi QoS,
    >>
    >> Thanks for your input.
    >>
    >> Do you mean the module Threads?
    >>
    >>
    >> <> wrote in message news:qr%gi.5424$ss5.76@trndny03...
    >> >
    >> > "Simon" <> wrote in message-id:
    >> > <zY_gi.458$>
    >> >
    >> >>

    > [snip]
    >> >> Connect to, say 10 machines all at the same time, then return data
    >> >> back
    >> >> to
    >> >> the one main console (where I executed the script in the first place),
    >> >> instead of waiting for 1 machine to end, then move on to the next.
    >> >>
    >> >> Any help greatly appreciated. Here is the script.
    >> >>

    > [snip]
    >> >> Any help greatly appreciated guys, thank you.
    >> >>
    >> >> S
    >> >
    >> > Just use Threads
    >> >

    >
    > Yeah have a look at:
    > perldoc perlthrtut
    > and
    > perldoc Threads
    > and
    > perldoc Threads::Shared
    >
    > HtH
    >
    > J
    >
     
    Simon, Jun 29, 2007
    #7
  8. Simon wrote:
    <snip>
    >
    > Thanks Joe..much appreciated.
    >
    > I do know Joe how to connect to a remote registry.
    >
    > I spose what Im trying to do, but cant get myself on some really really
    > simple examples, so i can play with them, are example scripts on how to fork
    > a process.
    > Ive looked at the perldoc but I find the doco not as clear as some good
    > beginner fork examples so I can test them out on my systems, then gain
    > confidence that way.
    >
    > Appreciate your help. :)
    >


    You could look at Parallel::ForkManager - it may make things easier for
    you.

    Mark
     
    Mark Clements, Jul 3, 2007
    #8
  9. Simon

    Simon Guest

    Thank you Mark...really appreciate it.

    "Mark Clements" <> wrote in message
    news:4689ea03$0$27393$...
    > Simon wrote:
    > <snip>
    > >
    >> Thanks Joe..much appreciated.
    >>
    >> I do know Joe how to connect to a remote registry.
    >>
    >> I spose what Im trying to do, but cant get myself on some really really
    >> simple examples, so i can play with them, are example scripts on how to
    >> fork a process.
    >> Ive looked at the perldoc but I find the doco not as clear as some good
    >> beginner fork examples so I can test them out on my systems, then gain
    >> confidence that way.
    >>
    >> Appreciate your help. :)
    >>

    >
    > You could look at Parallel::ForkManager - it may make things easier for
    > you.
    >
    > Mark
    >
    >
     
    Simon, Jul 4, 2007
    #9
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SSBhbSBTYW0=?=

    Datagrids are kicking my ass!! Please help

    =?Utf-8?B?SSBhbSBTYW0=?=, Mar 14, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    469
    JohnFol
    Mar 14, 2005
  2. Matt
    Replies:
    2
    Views:
    397
    Andrew Thompson
    Feb 25, 2004
  3. windandwaves

    kicking a list to visible into IE

    windandwaves, Aug 2, 2005, in forum: HTML
    Replies:
    3
    Views:
    468
    windandwaves
    Aug 5, 2005
  4. korean_dave
    Replies:
    2
    Views:
    502
    Lawrence D'Oliveiro
    Oct 19, 2008
  5. Martin DeMello
    Replies:
    1
    Views:
    224
    Farrel Lifson
    Nov 13, 2006
Loading...

Share This Page