Facing problem in checking the directory existence


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Facing problem in checking the directory existence
# 1  
Old 05-28-2009
Facing problem in checking the directory existence

Hi All,

I have a written a scell script which checks the existence of a directory. The dierctory name is read from property file. Though the dierctory exists but it says - it does not exist--
Find my code below --


#! /bin/ksh
#Tibco Properties file is inclusion
. TibcoInstall.properties
function InstallDirCheck
{
echo "Checking for $2 Installation Directory Existence"
if [ -d $1 ]; then
echo "$2 Installation Directory Exists"
else
echo "$2 Installation Directory does not Exists"
fi
}
InstallDirCheck $1 $2

Thanks
Supriya
# 2  
Old 05-28-2009
Put in quotes around.

if [ -d "$1" ]; then
# 3  
Old 05-28-2009
I am not able to understand how is the script reading the directory name from the property file.

what are the params you are passing, the first param seems to be the dir that you are passing. Can you please give some more input and an example of what you are passing
# 4  
Old 05-28-2009
Facing problem in checking the directory existence

#! /bin/ksh
#Tibco Properties file is inclusion
. TibcoInstall.properties

#Function To Check the TRA Installation Directory Existence
function InstallDirCheck
{
echo "Checking for $3 Installation Directory Existence"
if [ -d "$1" ]; then
echo "$3 Installation Directory Exists"
if [ -d "$2" ]; then
echo " $3 Script Base Directory Exists"
returnCheck="0"
else
echo " $3 Script Base Directory Does not Exist"
returnCheck="1"
fi
else
echo "$3 Installation Directory Does not Exist"
returnCheck="1"
fi
return $returnCheck
}
#Function To Check the BW Installation Directory Existence

function InstallFileCheck
{
echo "Checking for the TRA Installation Bin Files Existence"
# Check for FILE Existence
if [ ! -f $1 ]; then
echo "Installation List File $2 Does not Exists"
returnCheck="1"
else
echo "Installation List File $2 Exists"
let countValue=0
# Checking for each file existence in the List file
for i in $1
do
if [ ! -f $i ]; then
let countValue=countValue+1
fi
done
echo $countValue
if [ $countValue -gt 0 ]; then
echo "The required installables files listed in $2 are not Present"
returnCheck="1"
else
echo " The required $2 installables are Present"
returnCheck="0"
fi
fi
return $returnCheck
}

function InstallCall
{
#Installation Directory Existence Check
InstallDirCheck $1 $2 $5
let temp=$?
if [ $temp -eq "0" ]; then
#Installation Directory Existence Check
InstallFileCheck $3 $5
let temp1=$?
if [ $temp1 -eq "0" ]; then
ScriptCall $4 $5
exit 0
else
exit 1
fi
else
exit 1
fi
}
function ScriptCall
{
echo "Calling Installation Script $2"
./$base_script_dir/$1
}

function TibcoInstallCall
{
echo "TRA Installation Started"
InstallCall $base_install_dir_tra $base_script_dir_tra $tra_FileList $tra_script "TRA"
let temp= $?
if [ $temp -eq 0 ]; then
echo "TRA Installation Finished Successfully"
#BW Installation
echo "BW Installation Started"
InstallCall $base_install_dir_bw $base_script_dir_bw $bw_FileList $bw_script "BW"
let temp1=$?
if [ $temp1 -eq 0 ]; then
echo "BW Installation Finished Successfully"
#BC Installation
echo "BC installation Started"
InstallCall $base_install_dir_bc $base_script_dir_bc $bc_FileList $bc_script "BC"
echo "BC Installation Finished Successfully"
let temp2=$?
exit 0
else
exit 1
fi
else
exit 1
fi
}
echo "Installation of TIBCO Set Up starts"
echo "Enter your Input to continue"
echo " 1. Yes "
echo " 2. No "
read installInput
if [ "$installInput" = "2" ]; then
echo " Do You Want to Exit Installation wizard"
echo " Press 0.To Exit or 1. To Continue Installation"
read exCon
if [ "$exCon" = "0" ]; then
exit 0
else
TibcoInstallCall
fi
else
TibcoInstallCall
fi

-----Post Update-----

With quotes it did not work but when i hard code the directory name. it works fine.

Please let me know the solution for this.

Thanks
supriya

-----Post Update-----

#Domain and its Credentials
target_machine=nlvdhq498
target_user=sa_tibco_bc
target_install_script=/usr/admin/sysadm/home/sa_tibco_dva/B2B/BC/installUtilities.sh
Domain=dva
domain_user=admin
domain_pwd=admin
#Installation Base Dierctory
base_install_dir_tra=/distr/tibco/installations/baselayer/tra/
base_install_dir_bw=/distr/tibco/installations/baselayer/bw/
base_install_dir_bc=/distr/tibco/installations/baselayer/bc/
#Script File Base Directory
base_script_dir_tra=/distr/tibco/distribution/dva/baselayer/tra/
base_script_dir_bw=/distr/tibco/distribution/dva/baselayer/businessworks/
base_script_dir_bc=/distr/tibco/distribution/dva/baselayer/bc/
#TRA File List
tra_FileList=traFileList.txt
#BW File List
bw_FileList=bwFileList.txt
#BC File List
BC_FileList=bcFileList.txt
#TRA Script Name
tra_script=/distr/tibco/distribution/dva/baselayer/tra.sh
#BW Script Name
bw_script=/distr/tibco/distribution/dva/baselayer/bw.sh
#BC Script Name
BC_script=/distr/tibco/distribution/dva/baselayer/bc.sh
# 5  
Old 05-28-2009
Got it sorted, get the parameters in a variable and then check for there existence due to some reason $1 is not working in test condition.
I did this way and it works.
Code:
#!/usr/bin/ksh
DIR=$2
function InstallDirCheck
{
echo "Checking for $2 Installation Directory Existence"
if [ -d $DIR ]; then
echo "$2 Installation Directory Exists"
else
echo "$2 Installation Directory does not Exists"
fi
}

InstallDirCheck $1 $2


Last edited by dinjo_jo; 05-28-2009 at 06:11 AM..
# 6  
Old 05-28-2009
It got solved, The problem was cntrlM characters.

Thanks
Supriya.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command script for checking a file existence

Hello, I have a directory where sometimes appear a certain file name - and I'd like to be notified by email when that happens... so what command or script I may use? e.g. if there's a file named "adam" in the directory named "dir1" then send a mail to "abc@abc.com".. it needs to permanently... (5 Replies)
Discussion started by: netrom
5 Replies

2. Shell Programming and Scripting

Checking for the file existence

Hi, I have written a script to validate the data file by referreing to the configurtion file. And moving the validated good records and bad records into HDFS. Suppose after 15 mins if i receive one more data fie,then after validation the good and bad records shold be stored in hadoop with the... (8 Replies)
Discussion started by: shree11
8 Replies

3. Shell Programming and Scripting

Checking file existence along with condition

Hi am trying to write a script which find the existence of a file from a find command output and perform a task if the file exists. Help me out with the correct syntax . Am trying with the following one but unable to get the output. if then <some tasks> else echo "file not exists" fi (5 Replies)
Discussion started by: rogerben
5 Replies

4. Shell Programming and Scripting

Checking existence of file using awk

Hi, I need to check whether a particular file exists ot not using awk. Can anyone help me please? For Example:script that i am using: awk '{filename =$NF; rc=(system("test -r filename")) print $rc;}' "$1" is not working. Here I am passing a text file as input whose last word contains a... (6 Replies)
Discussion started by: manish007
6 Replies

5. Shell Programming and Scripting

checking the file existence using ssh

Hi Can any body say me the reason for below error ssh -o 'StrictHostKeyChecking no' user@client ' && print "1"' I am getting error as "Missing ]":wall: (6 Replies)
Discussion started by: ramesh12621
6 Replies

6. Shell Programming and Scripting

Checking the existence of a file before getting last modified

Hi, I am trying to check the existence of a file, from a list of possible filenames: status-A status-B status-C before retrieving the last modified datetime using ls, I want to check it exists or ls will throw an error. So I have tried this: if ; then ls status-* fi But the if... (3 Replies)
Discussion started by: LostInTheWoods
3 Replies

7. Shell Programming and Scripting

Checking Multiple file existence

Hi, I want to check multiple files exist or not in a single if statement in korn Shell:confused:. Please help me Thanks (1 Reply)
Discussion started by: lathish
1 Replies

8. Solaris

checking for existence of table in oracle

how do i check from solaris for existence of table in oracle..?? the requirement is, that if the table does not exist, it is created.. :confused: The logic will be something like: if table exists then insert into table else create table insert into table end if (0 Replies)
Discussion started by: kjs
0 Replies

9. Shell Programming and Scripting

Checking the existence of a file..

Hi, I am trying to check for the existence of a file using the 'test' and the file existence options. When trying to check for a file with a space in between e.g 'Team List', it gives the following error. learn1: line 3: test: `Team: binary operator expected I am pasting my code below as... (7 Replies)
Discussion started by: igandu
7 Replies

10. Shell Programming and Scripting

checking file existence

Hi, My requirement was to check the existence of a file having a specified pattern.The way i tried to achieve this was if ; then echo "File found" fi an example file having this pattern was 'ilvs_trace01.0124'. it will vary... (3 Replies)
Discussion started by: DILEEP410
3 Replies
Login or Register to Ask a Question