Bash Script for file auditing, push information to server and be able to view in a web page
Performance pitfalls

Running ssh in a loop tends to be slow. Running it twice for every file in a list is probably extremely slow. There's no easy fix for this. You need to rethink how to solve the problem of matching paths between two systems.

Off the top of my head:


Get the list of paths from both systems, and then try to match those locally. This can be done with one ssh call per system: a major improvement.
For the list of matched paths, get the md5 sums. Again this can be done with one ssh call per system.
Compare the hashes, and build a new list of mismatched files.
For the final comparison of files, you could fetch them one by one to conserve disk space. If the number of remaining files is expected to be small, then one scp call per file might be acceptable. Or if disk space is not an issue, then you could transfer all the files with one call.


A much smaller performance issue is running sed ... | column ... for each file type for each base directory. You could instead make the loop body output only the output of the multiple find calls, and run the sed ... pipeline on the entire loop (writing as done | sed ...).

Looping over arrays

Instead of this:


for((i=0; i&lt;${#DIR[@]}; i++)) 
do
  echo "CHECKING: ${DIR[$i]}"



When you don't need the array indexes, just the elements, you can iterate like this:

for dir in "${DIR[@]}"
do
  echo "CHECKING: $dir"


Most of the loops in the posted script can be replaced with this simpler, more intuitive style.

Simple mistakes


Use . instead of $PWD
Double-quote variables used in command arguments: instead of find $var, write find "$var"
Don't export if you don't need to
Don't create arrays if you need a simple variable: instead of tmpdir=("$_TMPDIR$path") write tmpdir="$_TMPDIR$path"
Strive for simple writing style: instead of env2file=(/"$ScriptsDir"/tmp"$x"), write env2file="$ScriptsDir/tmp$x"