Skip to content

Instantly share code, notes, and snippets.

@RichardBronosky
Created April 28, 2011 18:04
Show Gist options
  • Save RichardBronosky/946889 to your computer and use it in GitHub Desktop.
Save RichardBronosky/946889 to your computer and use it in GitHub Desktop.
A series of tests to find a viable solution for comparing directories between multiple hosts.
#!/usr/bin/env bash
# Create and cd into a new temp dir before running this series of tests.
p(){ echo; read -sn 1 -p "Press any key to continue..."; echo; echo;}
n(){ n=$1; echo -n "$ "; sed "$BASH_LINENO!d" $0; }
# Create
d=$(date +%y%m%d%H%M%S)
echo "Creating files...";
for f in cp mv rm ls tar xargs find; do ((d++)); echo $d $f; man $f > $f.txt; touch -t $(sed 's/\(..\)$/.\1/' <<< $d) $f.txt; done
echo "Done."; p;
echo "Creating workspace...";
o=(t r)
for n in 0 1; do
mkdir $n
for f in $(ls -${o[$n]} *.txt); do ((d++)); echo $d $f; cat $f > $n/$f; touch -t $(sed 's/\(..\)$/.\1/' <<< $d) $f; done
done
echo "Done."; p;
# Verify
for f in 0/*; do shasum $f ${f/0/1}; done; p;
# Tests
#set -x
n; time for d in 0 1; do (echo $d; cd $d; pwd; tar cvf - . | shasum); done; p;
n; time for d in 0 1; do (echo $d; cd $d; pwd; ls *.txt | cpio -o > ../$d.out); done; ls -l [01].out; shasum [01].out; p;
n; time for d in 0 1; do (echo $d; cd $d; pwd; find . -type f -print0| sort -z | xargs -0 shasum | shasum | cut -f1 -d' '); done; p;
n; time for d in 0 1; do (echo $d; cd $d; pwd; find . -type f -print0| sort -z | xargs -0 cat | shasum | cut -f1 -d' '); done; p;
@RichardBronosky
Copy link
Author

SAMPLE OUTPUT

./hash_tests.sh
Creating files...
110428140442 cp
110428140443 mv
110428140444 rm
110428140445 ls
110428140446 tar
110428140447 xargs
110428140448 find
Done.

Press any key to continue...

Creating workspace...
110428140449 find.txt
110428140450 xargs.txt
110428140451 tar.txt
110428140452 ls.txt
110428140453 rm.txt
110428140454 mv.txt
110428140455 cp.txt
110428140456 xargs.txt
110428140457 tar.txt
110428140458 rm.txt
110428140459 mv.txt
110428140460 ls.txt
110428140461 find.txt
110428140462 cp.txt
Done.

Press any key to continue...

369e917d49f1770735bb797193935b6e57d96eea 0/cp.txt
369e917d49f1770735bb797193935b6e57d96eea 1/cp.txt
a15d01584941491edb101a2e997a1b0330bc7904 0/find.txt
a15d01584941491edb101a2e997a1b0330bc7904 1/find.txt
ade488f06131be1e05f66fb42c527af4daaeb499 0/ls.txt
ade488f06131be1e05f66fb42c527af4daaeb499 1/ls.txt
08216618564deddd65b8b58bebe3291116a759ef 0/mv.txt
08216618564deddd65b8b58bebe3291116a759ef 1/mv.txt
9aa3b41aa12d8e21f9086a723d14278019025e4f 0/rm.txt
9aa3b41aa12d8e21f9086a723d14278019025e4f 1/rm.txt
8b56c25e96756a0ec91f8de3e7221bf5a79c340b 0/tar.txt
8b56c25e96756a0ec91f8de3e7221bf5a79c340b 1/tar.txt
61a932d2ad149c4a28df0b7d4bf198ba5b9368b7 0/xargs.txt
61a932d2ad149c4a28df0b7d4bf198ba5b9368b7 1/xargs.txt

Press any key to continue...

$ n; time for d in 0 1; do (echo $d; cd $d; pwd; tar cvf - . | shasum); done; p;
0
/tmp/files/0
a .
a ./cp.txt
a ./find.txt
a ./ls.txt
a ./mv.txt
a ./rm.txt
a ./tar.txt
a ./xargs.txt
78bb8346a4782559af9213b650fdb088d9b9c8aa -
1
/tmp/files/1
a .
a ./cp.txt
a ./find.txt
a ./ls.txt
a ./mv.txt
a ./rm.txt
a ./tar.txt
a ./xargs.txt
e89b719589275dcfd15e2267349b1846254a3bac -

real 0m0.238s
user 0m0.076s
sys 0m0.034s

Press any key to continue...

$ n; time for d in 0 1; do (echo $d; cd $d; pwd; ls *.txt | cpio -o > ../$d.out); done; ls -l [01].out; shasum [01].out; p;
0
/tmp/files/0
313 blocks
1
/tmp/files/1
313 blocks

real 0m0.055s
user 0m0.003s
sys 0m0.014s
-rw-r--r-- 1 rbronosky wheel 160256 Apr 28 14:04 0.out
-rw-r--r-- 1 rbronosky wheel 160256 Apr 28 14:04 1.out
177832c53abff803671d83eadd3e235ad11dc8cd 0.out
d0b9458309c93af3d30e30b0ed48455c4d1ed1ae 1.out

Press any key to continue...

$ n; time for d in 0 1; do (echo $d; cd $d; pwd; find . -type f -print0| sort -z | xargs -0 shasum | shasum | cut -f1 -d' '); done; p;
0
/tmp/files/0
15cf689b1c1ca5ac609164efed3ed35078d0f153
1
/tmp/files/1
15cf689b1c1ca5ac609164efed3ed35078d0f153

real 0m0.248s
user 0m0.155s
sys 0m0.076s

Press any key to continue...

$ n; time for d in 0 1; do (echo $d; cd $d; pwd; find . -type f -print0| sort -z | xargs -0 cat | shasum | cut -f1 -d' '); done; p;
0
/tmp/files/0
84f32c7c5a16a421e0dc318810610855ce5b8f01
1
/tmp/files/1
84f32c7c5a16a421e0dc318810610855ce5b8f01

real 0m0.171s
user 0m0.083s
sys 0m0.058s

Press any key to continue...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment