How to check directory exist on servers

There are many servers and their directory structer should be exactly the same. To check the directory path for all servers, I wrote a script.

#! /bin/ksh

ARRAY_DIRECTORIES[1]="/c/dev/custom/bin"
ARRAY_DIRECTORIES[2]="/c/dev/db/custom/src"

ARRAY_ENV[1]="remoteName200" 
ARRAY_ENV[2]="remoteName201"
ARRAY_ENV[3]="remoteName202"

integer DIR_INDEX=0
integer ENV_INDEX=0

while(($ENV_INDEX<3))
do
	ENV_INDE=`expr $ENV_INDE+1`
	
	ssh "${ARRAY_ENV[$ENV_INDE]}"

	while (($DIR_INDEX<2))
	do
		DIR_INDEX=`expr $DIR_INDEX + 1`
	
		if [ ! -d "${ARRAY_DIRECTORIES[$DIR_INDEX]}" ]
		then
			#do something
		fi
	done
done

I am new to Shell Scripting, maybe I am doing something really stupid and need your help.

The script does ssh to the server without asking for password (I put a ssh key to .ssh directory.)

Thanks
Mike

expr requires space around the terms (eg `expr $ENV_INDE + 1` not `expr $ENV_INDE+1`)
You are refering to ENV_INDE and ENV_INDEX seemingly interchangably - it looks like a typo or three there
ksh isn't required for this - you are restricting yourself without needing to, just use sh

If you want to go for ksh (i would recommend that, sorry, Smiling Dragon), you do not need the "`expr ....`"-constructs. Further, you terminate your loops based on your knowledge how many array entries there are (3 in your case). You could make that dynamic so you wouldn't have to change the code there if you add more entries to your arrays.

Notice that "${#arr[*]}" gives you the number of elements in the array "arr[]". Inside double brackets you can do integer math: "(( var3 = var1 + var2 ))". You have to surround the brackets with spaces, though. "((var1..." is wrong, "(( var1..." is ok.

typeset    arr[1]="first"
typeset   arr[2]="second"
typeset   arr[3]="third"
typeset   arr[4]="fourth"
typeset -i index=1

(( index = 1 ))
while [ $index -le ${#arr[*]} ] ; do
     print - "element to work on: ${arr[$index]}"
     (( index =+ 1 ))
done

I hope this helps.

bakunin