This is just a blog to try and spread some of the knowledge that has been freely given to me by the wider community, without which I'd get absolutely nothing accomplished. I hope this benefits some of you out there.

Showing posts with label compare conf files. Show all posts
Showing posts with label compare conf files. Show all posts

Friday, June 12, 2009

Bash Script for Comparing Two Conf Directories



I have had a small problem of screwing up my jboss the other day. To get it working again I had to copy my co-worker's jboss directories and start using that. Slight problem with that, all the conf files will now be specific to him and not me e.g. my jndi ports, etc. So I had to go through by hand and fix all of the conf files I could find. Luckily I had a backup of my old conf files to check against. In an effort to track down the differences I wrote the following bash script.

My bash is not good, but it seems to do the trick and will compare files in two directories who's only difference is the path.

#!/bin/bash

#List the files that end with 'xml' in the final directory of $1 (you specify $1
#as the first arg on the command line)
#Note that when you list with a wild card *nix will list out the full path. If you know how to disable that #for ls, then you can use that instead, but I didn't see anything in the man pages. Therfore, strip it #out with a quick and dirty regex

ls /home/blah/jboss/server/all/$1/*xml > dir

orig_jboss="/home/
blah/jboss-4.2.3.GA.20090611/server/all/$1/"
new_jboss="/home/
blah/jboss/server/all/$1/"

#note the >>. If you don't put both it will only write the last one into the new file.
#>> will force an append
for file in `cat dir`; do echo ${file#/home*$1/} >> actual_dir ; done

for i in `cat actual_dir`; do diff $new_jboss$i $orig_jboss$i ; done

#If you don't do this and run the script a few times, you'll keep appending more
#things into 'actual_dir'
rm dir actual_dir

If everything is the same you shouldn't see any output. Otherwise you'll get a list of all the differences without having to do much by hand.

Followers