Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Comparison of two hashed string failed, why?
February 21, 2009, 12:26 am
rate this thread
mnt/dir_nfs. To ensure an application behaves correctly over the
direct mount point and the NFS mount point, I wish to use a simple
minded strategy of comparing the hashed ls -lR output of both
subdirectories. If the two hashes differ, I consider the application
For testing, I simply did cd /mnt/dir_direct; touch hi_0 hi_1 hi_2,
and then run the code, which in highly condensed form is shown below.
When I ran the code as cd /tmp; php5 test.php, I got:
root@lab2:/mnt/dir_direct# touch hi_0 hi_1 hi_2
root@lab2:/mnt/dir_direct# ls -l
-rw-r--r-- 1 root root 0 Feb 20 16:16 hi_0
-rw-r--r-- 1 root root 0 Feb 20 16:16 hi_1
-rw-r--r-- 1 root root 0 Feb 20 16:16 hi_2
root@lab2:/mnt/dir_direct# cd /tmp
root@lab2:/tmp# php5 j0.php
For /mnt/dir_direct, md5 of ls -lR is
For /mnt/dir_nfs, md5 of ls -lR is 23a059bfac666ff52d83587717a9bd57.
The NFS test failed.
The two hashes are identical, but the code reports a failure. Unless
my eyes are really failing me, I can't spot the cause. Thanks for any
$direct_mount = "/mnt/dir_direct";
$nfs_mount = "/mnt/dir_nfs";
$dir_out = ls_lr($direct_mount);
$nfs_out = ls_lr($nfs_mount);
$dir_md5 = hash('md5', $dir_out);
$nfs_md5 = hash('md5', $nfs_out);
print "For $direct_mount, md5 of ls -lR is $dir_md5.\n";
print "For $nfs_mount, md5 of ls -lR is $dir_md5.\n";
if ($dir_md5 == $nfs_md5)
print "The NFS test passed.\n";
print "The NFS test failed.\n";
$ph = popen("/bin/ls -lR $dir", 'r') or die($php_errormsg);
$out = '';
while ($r = fgets($ph))
$out .= $r;