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!

sat($file)

Status
Not open for further replies.

wrxsti08

Programmer
Dec 27, 2007
2
US
Hello,

I'm new to this board and perl. I did some searching but coul dnot resolv emu issue.

I'm trying to get a file UID and GIU, and then set it if needed. I used stat, but in my code its returing nothing, litterly nothing. For . and .. it seems to work, but my testfile.txt nothing is returned. If I ls -al testfile.txt I see my user and group assigned to the file.

Why is...
$FileUser = (stat($file))[4];
$FileGroup = (stat($file))[5];
@FileArray = stat($file);
...returning nothing ? I'm running Komodo debug on SUSE 10.3.

TIA

Code:
for ($i=0; $i<@DcbDir; $i++)
{
$CurrentDir = $DcbDir[$i];
opendir(DIR, $CurrentDir) || die ("FAILURE: Cannot open $CurrentDir !\n");
@dirlist = readdir(DIR);
closedir(DIR);

print "CURRENT DIR: $CurrentDir \n\n";

foreach $file (@dirlist)
{
$FileUser = (stat($file))[4];
$FileGroup = (stat($file))[5];
@FileArray = stat($file);

if(($file eq '.') || ($file eq '..'))
{
next;
}

if(($FileGroup ne '100') || ($FileUser ne '1000'))
{
print "$CurrentDir$file is not in dcb group, $FileGroup, $FileUser, $file ! \n";
if (($file eq '.reports') && (-d $file))
{
#exec "chown -Rf sroot:dcb $CurrentDir$file";
chown(0, 503, $file);
}
else
{
#exec "chown -f sroot:dcb $CurrentDir$file";
chown(0, 503, $file);
}
}
#print "File group is: $FileGroup, File user is: $FileUser, $file \n";
}
}
 
Do you need to provide the full path to stat?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
This is a common problem.

Quick solution:

Code:
stat("$CurrentDir/$file");

The common problem is that, when you open a directory that's not the current working directory and try to manipulate files, you have to keep in mind that you're still trying to manipulate the file from your current working directory, NOT the directory you just opened. So always remember to use the directory name and the file name.

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
stat("$CurrentDir/$file");

...worked. I've learned something new... thank you for the detailed information I now understand why it was failing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top