Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NT Problems for Beginner

Status
Not open for further replies.

sucram

Programmer
May 23, 2001
75
GB
Hi everyone,
I have been given this code to modify. Basically I'm the only person who has any clue of perl but I don't know that much really. Would somebody be able to fill into the code below that is required to display the owner of the file. As it is the code works on NT and I have never written anything for NT. The code searches through directories and checks their details, I don't evn know if it is possible to get the owner of the file. I have never seen some of the stuff below and I don't even know why the 6th line would even compile.
Any help would be greatly appreciated.
Thanks for your time,
Marcus


#!/user/bin/perl
$time = 182;
$return = "c:\\Hlr\\hlrinfo.txt";
$path = "h:\\";
$c = 0;
dir[$c] = $path;
$c++;
open(OUT,">$return") || die "cannot open";

format OUT_TOP=

ALL FILES THAT HAVE NOT BEEN MODIFIED IN THE LAST 6
MONTHS:
==========================================================================================
Path | FileName

|Days since
|

|last Mofified
.
format OUT =
==========================================================================================


$path1


$name

$age2
.
format OUT1 =

$name

$age2
.

$old = select(OUT);
$= = 400000;
select($old);

for($b = 0;$b<$c;$b++){
$path1 = 0;
$path1 = dir[$b];
opendir(IN,&quot;$path1&quot;) || die &quot;cannot open&quot;;

$f = 0;
while($name = readdir(IN)){

$path2 = &quot;$path1\\$name&quot;;
if($name eq &quot;\.&quot;){
next;}
if($name eq &quot;\..&quot;){
next;}
if(-f $path2){
$age = (-M $path2);
$age1 = index($age,&quot;.&quot;);
$age2 = substr($age,0,$age1);
if($age > $time){
if($f == 0){
$oldHandle = select(OUT);
$~ = &quot;OUT&quot;;
select($oldHandle);
write OUT;
$f = 1;
}

elsif($f == 1){
$oldHandle = select(OUT);
$~ = &quot;OUT1&quot;;
select($oldHandle);
write OUT;
}
}
}
elsif(-d $path2){
dir[$c] = &quot;$path1\\$name&quot;;
$c++;
}

}

closedir(IN);

}
 
I would look at the &quot;stat&quot; function - it gives you back file attributes, including the numeric user ID of the file's Owner, and the numeric group ID of the file's Owner.

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
Another option would be to use backticks to execute a directory listing that would include the owner of the file - the output of the command will be returned to you - then you can parse the output for the file owner.

For example, on Linux if I wanted to get a directory listing, I could execute an &quot;ls -l&quot; command(I chose &quot;ls -l&quot; because it will display file attributes including the owner of the file) like this:

@ls_lines = `ls -l /dir/to/ls`;

Each element of array @ls_lines would contain one line of output from the ls command - to get the owner of a file, you'd then have to parse each line.

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
Thanks!

Do you think there would be any problems with that since it is running on an NT server, or would it just work as normal?

Marcus
 

It is possible to do a `dir -l` type command that will bring up the owners name on NT. I am having trouble finding where NT stores the owners name, it might help if I actually had an NT machine on my desk.

Thanks again,
Marcus

 
try executing &quot;subinacl&quot; from the NT command prompt. (it comes with the NT resource kit 2)

Code:
@ntFilestats = `subinacl /file <file name>`;

and the
Code:
@ntFilestats[3]
string should contain the owners name. This may be a little off (possibly way off) as im not at an NT machine at the moment either.
 

Thanks for the suggestions but nothing has worked so far.
The stat function returns nothing and `subinacl /file <file name>` gives an error

Any other suggestions would be welcome.

Thanks,
Marcus

 
Have you found out how to view the perldocs on NT? Does Perl on NT have a &quot;stat&quot; function? If it does, then there's no reason why it shouldn't work for you. I can't be much help since I'm not on NT, but I'd have to believe that the &quot;stat&quot; function was implemented on the Windows version of Perl. Make sure the filename you give to the stat function is an absolute filename(include the full path to the file).
Hardy Merrill
Mission Critical Linux, Inc.
 
Could someone tell me how to view the perldocs on NT I can't find them at all.
If someone knows the format of the stat function for NT I'd appreciate it if they could tell me, in unix the uid is held in the 5th element of the array, but in NT that only returns 0 all the time. This might mean that the uid is 0 but without the perldocs I have no way of knowing.

Thanks,
Marcus

 
to view perl docs, use the perldoc command from a command prompt.

C:\>perldoc -f stat <return>

That should give you the docmentation for the function of interest (stat, in this case).

You can get a help page for perldoc with
C:\>perldoc --help <return>

This is a very valuable resource.

HTH


keep the rudder amid ship and beware the odd typo
 

For anyone that is interested; on Windows 2000 `dir /q` will display the owner of the file (`ls -l` in Unix). This option is not available on older versions of windows.


Marcus



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top