Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > trying to create a network script:

Reply
Thread Tools

trying to create a network script:

 
 
Nex6
Guest
Posts: n/a
 
      02-06-2004
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
 
Reply With Quote
 
 
 
 
Bob Walton
Guest
Posts: n/a
 
      02-07-2004
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

 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      02-07-2004

http://www.velocityreviews.com/forums/(E-Mail Removed)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.
~ (E-Mail Removed) ~ Jorge Luis Borges, 'The Babylon Lottery'
 
Reply With Quote
 
Nex6
Guest
Posts: n/a
 
      02-10-2004
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:
> (E-Mail Removed)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
>

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      02-11-2004

[quoting fixed. please quote properly]

Nex6 <(E-Mail Removed)> 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. |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-| (E-Mail Removed)
 
Reply With Quote
 
Nex6
Guest
Posts: n/a
 
      02-11-2004
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 <(E-Mail Removed)> 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
>

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      02-11-2004
[STOP top-posting. Now.]

Nex6 <(E-Mail Removed)> 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)
* (E-Mail Removed) *
 
Reply With Quote
 
Nex6
Guest
Posts: n/a
 
      02-11-2004
Ben Morrow wrote:

> [STOP top-posting. Now.]
>
> Nex6 <(E-Mail Removed)> 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

 
Reply With Quote
 
Bob Walton
Guest
Posts: n/a
 
      02-11-2004
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

 
Reply With Quote
 
Nex6
Guest
Posts: n/a
 
      02-11-2004
Nex6 wrote:

> Ben Morrow wrote:
>
>> [STOP top-posting. Now.]
>>
>> Nex6 <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unexpected error when trying to create a network bridge in Windows =?Utf-8?B?Q3JhaWc=?= Wireless Networking 0 11-03-2005 10:17 AM
Trying to create a web application for wss john ASP .Net 0 02-26-2004 03:46 PM
Trying to create new web project SQL ASP .Net 1 01-21-2004 11:52 PM
Trying to create my first ASP.Net application Frank Wilson ASP .Net 6 08-14-2003 12:18 AM
Re: Trying to create a condition statement in KJ ASP .Net 0 07-23-2003 03:57 PM



Advertisments