I have a directory which is /home/mark/files/ , inside this particular I have a bunch of filles (see examples below)
TST_SHU_00014460_20090302.txt
TST_SHU_00016047_20090302.txt
TST_SHU_00007838_20090303.txt
TST_SHU_00056485_20090303.txt
TST_SHU_00014460_20090303.txt
TST_SHU_00014176_20090303.txt
And I also have another directory which is /home/dest/ which has the following dirs
00014460
00016047
00056485
As you can see, the directories matches a part of the files, inside each one of these directories i have subdirectories and anywhere inside these dirs the same files as in the first dir is copied there
I would like to have a shell script that would get the latest 10 file names created on the first dir (/home/mark/files/) and find them on the second dir /home/dest/ and when a file on the first directory has 0 bytes but on the second directory has data send me an e-mail and viscebersa when a file on the second directory has 0 bytes but the files on the first directory has data send me an email.
Thanks
Page 1 of 1
Need help with shell script to compare files in two dirs
#2
Posted 08 March 2009 - 08:09 AM
Hey there,
Here's a little command line version of what you need:
Just replace the:
with your sendmail or mailx, etc, command.
Hope that helps
, Mike
Here's a little command line version of what you need:
host # ls -tr files|tail -10|while read x;do if [ `du -sk files/$x|cut -f1` -eq 0 -o $(du -sk `find dest -name $x`|cut -f1) -eq 0 ]; then ls -l files/$x; ls -l `find dest -name $x`;fi;done
Quote
-rw-r--r-- 1 mgolvach None 0 Mar 8 01:50 files/TST_SHU_00056485_20090303.txt
-rw-r--r-- 1 mgolvach None 5 Mar 8 01:57 dest/00056485/TST_SHU_00056485_20090303.txt
-rw-r--r-- 1 mgolvach None 3 Mar 8 01:50 files/TST_SHU_00014460_20090303.txt
-rw-r--r-- 1 mgolvach None 0 Mar 8 01:56 dest/00014460/TST_SHU_00014460_20090303.txt
host #
-rw-r--r-- 1 mgolvach None 5 Mar 8 01:57 dest/00056485/TST_SHU_00056485_20090303.txt
-rw-r--r-- 1 mgolvach None 3 Mar 8 01:50 files/TST_SHU_00014460_20090303.txt
-rw-r--r-- 1 mgolvach None 0 Mar 8 01:56 dest/00014460/TST_SHU_00014460_20090303.txt
host #
Just replace the:
ls -l files/$x; ls -l `find dest -name $x`
with your sendmail or mailx, etc, command.
Hope that helps
, Mike
The greatest viral marketing idea of all time, get your copy of this Free Report now!
----
Linux Tips, Trick and Advice -- The Linux and Unix Menagerie
----
Linux Tips, Trick and Advice -- The Linux and Unix Menagerie
#3
Posted 08 March 2009 - 08:17 AM
Just a BTW,
If it helps, here's that command line in script form:
and if you have problems with variables inside the subshell created by piping to the while loop, you can write it with a simple redirect like this:
Best wishes,
Mike
If it helps, here's that command line in script form:
#!/bin/bash ls -tr files|tail -10|while read x do if [ `du -sk files/$x|cut -f1` -eq 0 -o $(du -sk `find dest -name $x`|cut -f1) -eq 0 ] then ls -l files/$x; ls -l `find dest -name $x` fi done
and if you have problems with variables inside the subshell created by piping to the while loop, you can write it with a simple redirect like this:
#!/bin/bash while read x do if [ `du -sk files/$x|cut -f1` -eq 0 -o $(du -sk `find dest -name $x`|cut -f1) -eq 0 ] then ls -l files/$x; ls -l `find dest -name $x` fi done <<<"`ls -tr files|tail -10`"
Best wishes,
Mike
The greatest viral marketing idea of all time, get your copy of this Free Report now!
----
Linux Tips, Trick and Advice -- The Linux and Unix Menagerie
----
Linux Tips, Trick and Advice -- The Linux and Unix Menagerie
Page 1 of 1

Sign In
Register
Help


MultiQuote