trying to create a network script:

N

Nex6

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
 
B

Bob Walton

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.


....


HTH.
 
B

Ben Morrow

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
 
N

Nex6

It did not work,

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

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



-Nex6
 
B

Ben Morrow

[quoting fixed. please quote properly]

Nex6 said:
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
 
N

Nex6

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 said:
[quoting fixed. please quote properly]

Nex6 said:
Ben Morrow wrote:



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
 
B

Ben Morrow

[STOP top-posting. Now.]

Nex6 said:
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
 
N

Nex6

Ben said:
[STOP top-posting. Now.]

Nex6 said:
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
 
B

Bob Walton

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"}
 
N

Nex6

Nex6 said:
Ben said:
[STOP top-posting. Now.]

Nex6 said:
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
 
B

Ben Morrow

Use forward slashes.

This is single-quoted. Single quotes do not interpolate variables.
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top