trying to create a network script:

Discussion in 'Perl Misc' started by Nex6, Feb 6, 2004.

  1. Nex6

    Nex6 Guest

    Hello all:


    Ok, This is what I am trying to do:

    I have a group of machines of maybe 200 workstations running NT 4.0
    workstation. They are on Policy.

    I want to push out some changes but the changes MUST happen in a
    controlled and safe way. as these are production machines.

    the gist of it is like this,

    connect to machine1
    make changes to reset.reg
    make changes to registry
    make change to domain account that matches machine.

    connect to machine2
    make changes to reset.reg
    make changes to registry
    make change to domain account that matches machine.


    etc etc etc.....


    I will be running this from a windows 2000 pro machnie running active
    state perl.

    so this is what I am thinking, have perl, pull the machine name from a
    text file and use that as a $var to pass it to open and the other
    statements and wrap the whole thing in a for or for each loop.

    I am having some trouble get it to work , i am working on the text pull
    now so any help would really be great!!!


    /code:

    open loc, "<testpull.txt";
    #my $file = '+<\\\\dsmccsb264da\\c$\\reset.reg';
    $file = <loc>;
    #$file = '+<\\\\dsmccsb264da\\c$\\reset.reg';


    $oldpass = '"password"'; #put old password here
    $newpass = '"newpass"'; #put NEW password here
    #print $file;
    open fh, '+<\\\\$file\\c$\\reset.reg' or die "can't open $file: $!";


    $slurp = join '', <fh>;

    $slurp =~ s/$oldpass/$newpass/ig;

    seek(fh,0,0);
    print fh $slurp;


    truncate(fh,tell(fh));


    close(fh);
    close(loc);

    /end code:

    This is what i have so far,
    when everything is staticd in it works, but now I need to pull just the
    machine name and use it becuase later i will need to use the same var to
    make the domain controller change.


    where it seem to have issues is connecting to the file , perl seems to
    be have trouble with the $file and pass it and such.

    Thanks!!!!



    -Nex6
     
    Nex6, Feb 6, 2004
    #1
    1. Advertising

  2. Nex6

    Bob Walton Guest

    Nex6 wrote:

    ....
    > open fh, '+<\\\\$file\\c$\\reset.reg' or die "can't open $file: $!";


    -----------^------^^^^^---------------^
    $file won't get interpolated in a '-quoted string. So you will attempt
    to open the literal \\$file\c$\reset.reg, which probably doesn't exist.
    I assume you have admin authority on the computers you are accessing;
    otherwise you will get a permission denied error when going the c$ route.

    Better is probably something like:

    open FH,"+<//$file/c\$/reset.reg" or die "Can't open $file: $!";

    (FH uppercase by convention, so it will never conflict with possible
    future reserved keywords in future versions of Perl). Also, Perl
    permits you to use / instead of \ as path separators on Windoze, which
    makes it a bit easier since you don't have to quote the /'s. And note
    that you need to quote the $ in this case.

    Also, your code was conspicuously missing the following:

    use strict;
    use warnings;

    Let Perl help you -- use those two.


    ....


    > -Nex6


    HTH.
    --
    Bob Walton
    Email: http://bwalton.com/cgi-bin/emailbob.pl
     
    Bob Walton, Feb 7, 2004
    #2
    1. Advertising

  3. Nex6

    Ben Morrow Guest

    d wrote:
    > Nex6 wrote:
    > > open fh, '+<\\\\$file\\c$\\reset.reg' or die "can't open $file: $!";

    >
    > Better is probably something like:
    >
    > open FH,"+<//$file/c\$/reset.reg" or die "Can't open $file: $!";


    Better again is

    open my $FH, '+<', "//$file/c\$/reset.reg" or die "can't open $file: $!";

    The lexical FH will close automatically when it goes out of scope.

    Ben

    --
    Like all men in Babylon I have been a proconsul; like all, a slave ... During
    one lunar year, I have been declared invisible; I shrieked and was not heard,
    I stole my bread and was not decapitated.
    ~ ~ Jorge Luis Borges, 'The Babylon Lottery'
     
    Ben Morrow, Feb 7, 2004
    #3
  4. Nex6

    Nex6 Guest

    It did not work,

    it just says can't open file....

    no matter how i try and open it, it does njot open.????



    -Nex6



    Ben Morrow wrote:
    > d wrote:
    >
    >>Nex6 wrote:
    >>
    >>>open fh, '+<\\\\$file\\c$\\reset.reg' or die "can't open $file: $!";

    >>
    >>Better is probably something like:
    >>
    >>open FH,"+<//$file/c\$/reset.reg" or die "Can't open $file: $!";

    >
    >
    > Better again is
    >
    > open my $FH, '+<', "//$file/c\$/reset.reg" or die "can't open $file: $!";
    >
    > The lexical FH will close automatically when it goes out of scope.
    >
    > Ben
    >
     
    Nex6, Feb 10, 2004
    #4
  5. Nex6

    Ben Morrow Guest

    [quoting fixed. please quote properly]

    Nex6 <> wrote:
    > Ben Morrow wrote:
    >
    > > open my $FH, '+<', "//$file/c\$/reset.reg" or die "can't open $file: $!";

    >
    > It did not work,
    >
    > it just says can't open file....


    can't open file... what? There should be an error message. If there
    isn't, change the $! to $^E.

    > no matter how i try and open it, it does njot open.????


    Do you have permission? Can you open the file in Explorer, as the user
    the perl script is running as?

    I have to admit my knowledge of Windows Networking is hazy at best,
    but I wouldn't usually have used one of the $ shares: what happens if
    you create an ordinary share?

    Ben

    --
    I've seen things you people wouldn't believe: attack ships on fire off the
    shoulder of Orion; I've watched C-beams glitter in the darkness near the
    Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
    Time to die. |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-|
     
    Ben Morrow, Feb 11, 2004
    #5
  6. Nex6

    Nex6 Guest

    can't open computername
    : No such file or directory at
    H:\scripts\admin-scripts\perl\cclinchgpassv2.pl line 27, <lc1> line 1.

    is the error msg,


    and the permissions are fine , if i run the script with static values
    instead of a $file text pull it works.



    -Nex6



    Ben Morrow wrote:
    > [quoting fixed. please quote properly]
    >
    > Nex6 <> wrote:
    >
    >>Ben Morrow wrote:
    >>
    >>
    >>>open my $FH, '+<', "//$file/c\$/reset.reg" or die "can't open $file: $!";

    >>
    >>It did not work,
    >>
    >>it just says can't open file....

    >
    >
    > can't open file... what? There should be an error message. If there
    > isn't, change the $! to $^E.
    >
    >
    >>no matter how i try and open it, it does njot open.????

    >
    >
    > Do you have permission? Can you open the file in Explorer, as the user
    > the perl script is running as?
    >
    > I have to admit my knowledge of Windows Networking is hazy at best,
    > but I wouldn't usually have used one of the $ shares: what happens if
    > you create an ordinary share?
    >
    > Ben
    >
     
    Nex6, Feb 11, 2004
    #6
  7. Nex6

    Ben Morrow Guest

    [STOP top-posting. Now.]

    Nex6 <> wrote:
    > Ben Morrow wrote:
    > >
    > > Do you have permission? Can you open the file in Explorer, as the user
    > > the perl script is running as?

    >
    > can't open computername
    > : No such file or directory at
    > H:\scripts\admin-scripts\perl\cclinchgpassv2.pl line 27, <lc1> line 1.
    >
    > is the error msg,
    >
    > and the permissions are fine , if i run the script with static values
    > instead of a $file text pull it works.


    Well then, the chances are that the computer specified in the variable
    doesn't exist, aren't they?

    Ben

    --
    And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
    * *
     
    Ben Morrow, Feb 11, 2004
    #7
  8. Nex6

    Nex6 Guest

    Ben Morrow wrote:

    > [STOP top-posting. Now.]
    >
    > Nex6 <> wrote:
    >
    >>Ben Morrow wrote:
    >>
    >>>Do you have permission? Can you open the file in Explorer, as the user
    >>>the perl script is running as?

    >>
    >>can't open computername
    >>: No such file or directory at
    >>H:\scripts\admin-scripts\perl\cclinchgpassv2.pl line 27, <lc1> line 1.
    >>
    >>is the error msg,
    >>
    >>and the permissions are fine , if i run the script with static values
    >>instead of a $file text pull it works.

    >
    >
    > Well then, the chances are that the computer specified in the variable
    > doesn't exist, aren't they?
    >
    > Ben
    >

    It does exist,

    if i mage the $var a static like:
    my $file = '+<\\\\computername\\c$\\reset.reg'

    it works


    if I :
    open my $fh1, '+<', '\\\\$file\\C$\\reset.reg' or die "can't open $file:
    $^E";

    it does not with $file being a text file with the computer name


    a detailed error is:


    H:\scripts\admin-scripts\perl>cclinchgpassv2.pl
    can't open computername: The network path was not found at
    H:\scripts\admin-scripts\perl\cclinchgpassv2.pl line 28, <lc1> lin
    e 1.

    -Nex6
     
    Nex6, Feb 11, 2004
    #8
  9. Nex6

    Bob Walton Guest

    Nex6 wrote:

    ....
    > if i mage the $var a static like:
    > my $file = '+<\\\\computername\\c$\\reset.reg'
    >
    > it works
    >
    >
    > if I :
    > open my $fh1, '+<', '\\\\$file\\C$\\reset.reg' or die "can't open $file:
    > $^E";
    >
    > it does not with $file being a text file with the computer name
    >
    >
    > a detailed error is:
    >
    >
    > H:\scripts\admin-scripts\perl>cclinchgpassv2.pl
    > can't open computername: The network path was not found at
    > H:\scripts\admin-scripts\perl\cclinchgpassv2.pl line 28, <lc1> lin
    > e 1.
    >
    > -Nex6
    >


    I recommend you carefully check $file for the presence of non-printing
    characters, the most likely being a newline at the end. You can use the
    length() function to verify the length, or the ord() function to print
    out the character code for each character like [untested]:

    for(split //,$file){print ord,"\n"}

    --
    Bob Walton
    Email: http://bwalton.com/cgi-bin/emailbob.pl
     
    Bob Walton, Feb 11, 2004
    #9
  10. Nex6

    Nex6 Guest

    Nex6 wrote:

    > Ben Morrow wrote:
    >
    >> [STOP top-posting. Now.]
    >>
    >> Nex6 <> wrote:
    >>
    >>> Ben Morrow wrote:
    >>>
    >>>> Do you have permission? Can you open the file in Explorer, as the user
    >>>> the perl script is running as?
    >>>
    >>>
    >>> can't open computername
    >>> : No such file or directory at
    >>> H:\scripts\admin-scripts\perl\cclinchgpassv2.pl line 27, <lc1> line 1.
    >>>
    >>> is the error msg,
    >>>
    >>> and the permissions are fine , if i run the script with static values
    >>> instead of a $file text pull it works.

    >>
    >>
    >>
    >> Well then, the chances are that the computer specified in the variable
    >> doesn't exist, aren't they?
    >>
    >> Ben
    >>

    > It does exist,
    >
    > if i mage the $var a static like:
    > my $file = '+<\\\\computername\\c$\\reset.reg'
    >
    > it works
    >
    >
    > if I :
    > open my $fh1, '+<', '\\\\$file\\C$\\reset.reg' or die "can't open $file:
    > $^E";
    >
    > it does not with $file being a text file with the computer name
    >
    >
    > a detailed error is:
    >
    >
    > H:\scripts\admin-scripts\perl>cclinchgpassv2.pl
    > can't open computername: The network path was not found at
    > H:\scripts\admin-scripts\perl\cclinchgpassv2.pl line 28, <lc1> lin
    > e 1.
    >
    > -Nex6
    >



    problem sloved:

    is removed c$ and chged it to $a

    and made $a = 'c$';

    and it worked


    -Nex6
     
    Nex6, Feb 11, 2004
    #10
  11. Nex6

    Ben Morrow Guest

    Nex6 <> wrote:
    > Nex6 wrote:
    >
    > > It does exist,
    > >
    > > if i mage the $var a static like:
    > > my $file = '+<\\\\computername\\c$\\reset.reg'


    Use forward slashes.

    > >
    > > it works
    > >
    > >
    > > if I :
    > > open my $fh1, '+<', '\\\\$file\\C$\\reset.reg'


    This is single-quoted. Single quotes do not interpolate variables.

    > > or die "can't open $file: $^E";

    >
    > problem sloved:


    ['Twas brillig... :)]

    > is removed c$ and chged it to $a
    >
    > and made $a = 'c$';
    >
    > and it worked


    You must have also changed your single to double quotes; in which case
    you would need to change the 'c$' to "c\$", as double quotes
    interpolate variables (in this instance, $\).

    Ben

    --
    Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
    From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
    (Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
    /Alcestis/) [ flame, and falls out of sight. ]
     
    Ben Morrow, Feb 11, 2004
    #11
    1. Advertising

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. Kal
    Replies:
    1
    Views:
    9,538
    Kevin Spencer
    Jun 21, 2004
  2. Jane Davis

    Network Service account over network

    Jane Davis, Jun 22, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    457
    Kevin Spencer
    Jun 22, 2005
  3. Bill Volk
    Replies:
    1
    Views:
    3,156
    Bill Volk
    Jul 2, 2003
  4. kin
    Replies:
    0
    Views:
    922
  5. Lutz Horn
    Replies:
    0
    Views:
    146
    Lutz Horn
    Aug 10, 2012
Loading...

Share This Page