I have this thing I have to do in Unix. It's easy - but very tedious. I have to do an 'sdiff' on two files and e-mail the results to myself for documentation purposes. But I'm not UNIX-savvy (yet) and even less KSH savvy. (I just learned what KSH stood for today!)
Here's what I need. I need a script that will do the following. This is what I have to type today:
sdiff really_long_program_name_here.ext /directory/where/other/file/is/really_lo
Yeah - I have to type that for every file that gets changed. There are 700 programs in the current product that I have to maintain. Nice.
Here's what I'd like to type:
supc file1 file2 file3 filen -f folder
Where:
- supc is the name of the script to be executed
- file1 is the first set of files to be compared
- file2 is the second set (and so on)
- -f folder is the folder where the second file I'm comparing against lives
Make sense?
This would REALLY make my life easier.
D
November 3 2005, 20:18:26 UTC 6 years ago
grep directory
--from-file=FILE1 Compare FILE1 to all operands. FILE1 can be a directory.
--to-file=FILE2 Compare all operands to FILE2. FILE2 can be a directory.
something like diff > file | mail -s .... ?
November 3 2005, 20:18:46 UTC 6 years ago
$ diff --help | grep directory
--from-file=FILE1 Compare FILE1 to all operands. FILE1 can be a directory.
--to-file=FILE2 Compare all operands to FILE2. FILE2 can be a direct
November 3 2005, 20:48:26 UTC 6 years ago
Of course,
Having said that... here's a roughed-out version. I haven't bothered to test it (bedtime) so you'll need to play with it a bit, but it should be close to the mark. Discussions welcome, especially if people have suggestions of better ways to do things.
November 3 2005, 20:53:09 UTC 6 years ago
#!/bin/ksh die () { echo "$(basename $0): fatal error: $*" >&2 exit 1 } # # Standard argument-parsing rubric # while getopts "e:f:" opt "$@" do case $opt in e) email="$OPTARG" ;; f) dir="$OPTARG" ;; *) die "bad option: '-$opt'" >&2 ;; esac done shift $((OPTIND - 1)) # # Check that the options are sensible # [[ -d $dir ]] || die "directory argument needed: -f '${dir:-}'" [[ -n $email ]] || die "email address needed: -e '${email:-}'" for file1 in "$@" do # # work out where the target file should be # file2="$dir/$(basename $file1)" # # check that the source and target file both exist # if not, move on to the next file # for f in "$file1" "$file2" do if [[ ! -f $f || ! -r $f ]] then echo "can't read file: '$f'" >&2 continue fi done # # diff and mail! # # You almost certainly want something that skips # identical files! # sdiff "$file1" "$file2" | mail -s "sdiff result: $file1" "$email" doneNovember 4 2005, 01:54:11 UTC 6 years ago
There would be no need for the emailed sdiff; all that would be necessary is to install cvsweb on top of the base CVS installation.