![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| check the directory exist | ust | Shell Programming and Scripting | 7 | 09-22-2008 08:49 PM |
| Check if certain files exist in a directory, if not add name to a textfile | SunnyK | Shell Programming and Scripting | 1 | 02-07-2008 09:21 AM |
| how to check if directory/file exist using c/c++ | steven88 | High Level Programming | 2 | 01-03-2006 02:55 AM |
| how to check if directory/file exist using c/c++ | steven88 | Shell Programming and Scripting | 1 | 01-02-2006 10:45 PM |
| how to check if the file exist or not? | gusla | UNIX for Dummies Questions & Answers | 3 | 03-27-2002 10:56 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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.
Code:
#! /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
The script does ssh to the server without asking for password (I put a ssh key to .ssh directory.) Thanks Mike |
|
||||
|
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. Code:
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
bakunin |
| Sponsored Links | ||
|
|