-3

i want to write a unix script where:

source dir:/test1/jobs/def1,def2,def3....so on target dir:/test2/jobs/def1,def2,def3....so on

scenario1: i want to compare that jobs folder in source and target directory both has exactly same no of files like def1,def2,def3 and so on.. and if there is any file not found in target it should capture that discrepency in log file.

scenario2: now once file level checking is done :

source dir:/test1/jobs/def1,def2,def3,mam1,mam2,mam3,mam4,try1,try2,try3,cus1,cus2,cus3,kit1,kit2,kit3.....so on

target dir:/test2/jobs/def1,def2,def3,mam1,mam2,mam3,mam4,try1,try2,try3,cus1,cus2,cus3,kit1,kit2,kit3.....so on

now i need to write a script where i should pass input parameter on run time as string like for eg if i give 'def'than script should compare the content of files starting with def only from source to target not all others.. and if content is mis matched than it should be captured in my log file.

Any help is much appreciated. Thanks in advance. J

neo
  • 89
  • 4
  • 11
  • 1
    show us what you have tried already – abasu May 21 '13 at 17:51
  • hey abasu.. i m new to this unix scripting and have no idea how to go about it.. please guide if u have any workaround. – jaishree vyas May 21 '13 at 17:58
  • you can check `diff` command http://www.unix.com/unix-dummies-questions-answers/27159-perform-diff-between-2-directories.html http://unixhelp.ed.ac.uk/CGI/man-cgi?diff – abasu May 21 '13 at 18:05

1 Answers1

0

You don't need a script. What you need is a tool built for comparing files and/or directories. You could try Meld or Git.

For instance, here is an example of how this could be done with Git:

$ cd test1
$ git init
$ git add .
$ git commit -m "Add source files"
$ git branch -M master source
$ cd ../test2
$ mv ../test1/.git .
$ git checkout -b target
$ git add .
$ git commit -m "Add target files"

That sets you up with a Git repository that contains both the "source" and "target" files. Then you can compare them like this:

$ git diff source target             # Compares everything
$ git diff source target jobs/def*   # Compares only "def" directories
Dan Moulding
  • 211,373
  • 23
  • 97
  • 98
  • git is a bit overkill - it's going to create and store a complete basis for *reproducing* the data. diff should be sufficient. – Chris Stratton May 21 '13 at 18:43
  • @ChrisStratton For most of what OP wants, I agree that `diff` is sufficient. But I see no way to get `diff` to show differences between all directories beginning with "def" or "mam", etc., without doing some scripting. – Dan Moulding May 21 '13 at 19:45
  • Scripting seems to be what the question title anticipates – Chris Stratton May 21 '13 at 19:53
  • @ChrisStratton True, but I suspect that OP doesn't really *want* to write a script, but thinks it is necessary. – Dan Moulding May 22 '13 at 10:20