Hi all;
I have the following code which gives me kind of what I need:
#!/usr/bin/perl
use Fcntl ':mode';
#
if ($ARGV[0] ne "") {
$filename = $ARGV[0];
} else {
print "Please specify a file!\n";
exit;
}
#
if (($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = lstat($filename)) {
$user = getpwuid($uid);
$group = getgrgid($gid);
#
$ftypes[S_IFDIR] = "d";
$ftypes[S_IFCHR] = "c";
$ftypes[S_IFBLK] = "b";
$ftypes[S_IFREG] = "-";
$ftypes[S_IFIFO] = "p";
$ftypes[S_IFLNK] = "l";
$ftypes[S_IFSOCK] = "s";
#
$permissions = sprintf "%04o", S_IMODE($mode);
$filetype = S_IFMT($mode);
#
$ftype = $ftypes[$filetype];
#
print "File: $filename\n";
printf "File mode: %o (%d)\n", $mode, $mode;
printf "File type: %s (%o)\n", $ftype, $filetype;
print "File permissions: $permissions\n";
print "File size: $size\n";
print "File owner user: $user\n";
print "File group: $group\n";
} else {
print "Please specify an EXISTING file!\n";
}
And this is how it works:
root@ubuntu:/usr/include# /tmp/stat.pl /tmp/stat.pl
File: /tmp/stat.pl
File mode: 100755 (33261)
File type: - (100000)
File permissions: 0755
File size: 918
File owner user: greys
File group: greys
But what I really need is to:
- find only directories and files with 777 permission on HP and Linux servers; so I want one script where I can ssh to each server and grab a listing of all 777 dir\files and put them in a comma delimited file
2.After getting the data into the file I need to then write it to a MySQL DB called audit into a table called myperms; I need to do this for about 25 servers - In Type; if it's a dir the script does put a "d" and that's what I want written to the table but I want "f" if it's a file not an "-".
I am failry new to perl; however I know how to connect to my MySQL and open a file to get data. My shorcomings in Perl though is that I do not know how to write data into a table. Also I do not know how I can modify the abaove script to start checking from the root "/" and go through the entitre server...how to get all server (a loop maybe?)
Here's a sample of some server names that you can use.
gmpsrv, mmmsrv, fidsrv
Hope someone can help me out.
Thanks all in advance
Regards
Giuliano