 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
snoopy_@excite.com Guest
|
Posted: Tue Dec 19, 2006 9:01 pm Post subject: Need help in comparing permissions/ownerships on different s |
|
|
Hello,
I am looking for help or suggestion for a way to compare
filesystems between two different systems. I have two development
environments, one is stable the other is not. I like to get a report
of how similar they are, and if the permissions are similar.
I tried rsync, but it doesn't tell you what is wrong with the file
or why it needs to be synced.
The other method is to run a find on one server, capture that as a
source csv file, then write a script to run through all those files and
compare them against the second hosts. I tried to use Perl's
File::stat for this, but was unsuccessful. I resorted to the
following:
find /d00 -print | xargs ls -ld | awk '{print $1","$3","$4","$9}' | tee
/tmp/find.out.csv
It results in a csv file contining perms on one system, then I could
use this to compare:
-rw-rw----,egatereg,egateg,/d00/app/home/egatereg/schemas/ss.runtime.tar
-rw-rw----,egatereg,egateg,/d00/app/home/egatereg/schemas/trn.modules.dat
-rw-rw----,egatereg,egateg,/d00/app/home/egatereg/schemas/trn.runtime.tar
Not how to interpret "-rwx" fields. Thought of perl with expression
matching, or using the File:stat modules. Doesn't seem pratical.
Any other ideas?
Thanks,
Snoopy_ |
|
| Back to top |
|
 |
Ayaz Ahmed Khan Guest
|
Posted: Tue Dec 19, 2006 10:21 pm Post subject: Re: Need help in comparing permissions/ownerships on differe |
|
|
"snoopy_ (AT) excite (DOT) com" typed:
[Follow-up set to comp.lang.perl.misc]
| Quote: | It results in a csv file contining perms on one system, then I could
use this to compare:
-rw-rw----,egatereg,egateg,/d00/app/home/egatereg/schemas/ss.runtime.tar
-rw-rw----,egatereg,egateg,/d00/app/home/egatereg/schemas/trn.modules.dat
-rw-rw----,egatereg,egateg,/d00/app/home/egatereg/schemas/trn.runtime.tar
Not how to interpret "-rwx" fields. Thought of perl with expression
matching, or using the File:stat modules. Doesn't seem pratical.
Any other ideas?
|
I once had a need to do something similar. I never completed the
application. The need either thined away into insignificance, or the
damage done wasn't so serious as had been presumed initially (the lead web
developer had accidentaly run `chmod -R 777 /` on one production system I
administrate). Nonetheless, the following snippet from the application
might help you. You might want to use a different module to traverse the
filesystem, as File::Glob doesn't quite work as I wanted it to.
sub read_filesystem
{
my $startpath = shift;
# Limitation: Doesn't do recursive globbing.
use File::Glob ':glob';
my @files = glob($startpath);
use File::Stat::Ls qw(:all);
foreach my $file (@files) {
my @filestat = stat($file);
my ($mode, $uid, $gid) = ($filestat[2], $filestat[4], $filestat[5]);
my $file_obj = File::Stat::Ls->new;
my $perm = $file_obj->format_mode($mode);
my $octal = &convert_to_octal($perm);
# Quick hack to workaround the fact that directory entries read from
# MANIFEST have a trailing "/" character attached to them. Globbing
# does not behave the same way with respect to directory entries.
$file .= "/" if -d $file;
$fs_live{$file} = [$uid, $gid, $perm, $octal];
}
}
###
### Given a string like "-rwx-r-xr-x", return equivalent octal representation.
###
sub convert_to_octal
{
my $perm = shift;
my $octal;
my ($special, $user, $group, $other) = (0, 0, 0, 0);
my ($x, $ur, $uw, $ux, $gr, $gw, $gx, $or, $ow, $ox) = split //, $perm;
$user += 4 if $ur eq 'r';
$user += 2 if $uw eq 'w';
$user += 1 if $ux eq 'x';
if ($ux eq 's') { $user += 1; $special += 4; }
$group += 4 if $gr eq 'r';
$group += 2 if $gw eq 'w';
$group += 1 if $gx eq 'x';
if ($gx eq 's') { $group += 1; $special += 2; }
$other += 4 if $or eq 'r';
$other += 2 if $ow eq 'w';
$other += 1 if $ox eq 'x';
if ($ox eq 't') { $other += 1; $special += 1; }
$octal = $special . $user . $group . $other;
return $octal;
}
I suggest reading through a few tutorials explaining Unix/Linux file modes
and permissions.
--
Ayaz Ahmed Khan
It is impossible to defend perfectly against the attack of those who
want to die. |
|
| Back to top |
|
 |
Hemal Pandya Guest
|
Posted: Wed Dec 20, 2006 8:11 am Post subject: Re: Need help in comparing permissions/ownerships on differe |
|
|
snoopy_ wrote:
| Quote: | Hello,
I am looking for help or suggestion for a way to compare
filesystems between two different systems. I have two development
environments, one is stable the other is not. I like to get a report
of how similar they are, and if the permissions are similar.
I tried rsync, but it doesn't tell you what is wrong with the file
or why it needs to be synced.
|
Actually it does. Try the --dry-run option with -vv.
| Quote: |
The other method is to run a find on one server, capture that as a
source csv file, then write a script to run through all those files and
compare them against the second hosts. I tried to use Perl's
File::stat for this, but was unsuccessful. I resorted to the
following:
find /d00 -print | xargs ls -ld | awk '{print $1","$3","$4","$9}' | tee
/tmp/find.out.csv
It results in a csv file contining perms on one system, then I could
use this to compare:
-rw-rw----,egatereg,egateg,/d00/app/home/egatereg/schemas/ss.runtime.tar
-rw-rw----,egatereg,egateg,/d00/app/home/egatereg/schemas/trn.modules.dat
-rw-rw----,egatereg,egateg,/d00/app/home/egatereg/schemas/trn.runtime.tar
Not how to interpret "-rwx" fields. Thought of perl with expression
matching, or using the File:stat modules. Doesn't seem pratical.
|
Are you looking to separate the three "rwx"? Look at cut.
Even without that, comparing the output on the dev and production boxes
using diff will give you the differences. If the production and dev
boxes are rooted in different directories,
instead of find <dir> -print, use (cd <dir>; find . print) then the
output will not have initial path..
What does this have to do with java?
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|