To find wether given entry is a file or directory
- From: "nitesh.reddy@xxxxxxxxx" <nitesh.reddy@xxxxxxxxx>
- Date: 2 Mar 2007 10:43:15 -0800
Hi
In this script i have to check whether the dest_dir is a file or
directory.
I used -d and -f command to check wether it is a directory or file. It
always
executes the else command with out executing if statments. Is there
any other way to find whether it is a file or directory
The entry is located on a remote computer. You dont have to login to
access the remote computer. We can directly access the remote
computer.
Is the usage of basename command valid.
#!/usr/bin/ksh
# to turn on the execution trace
#set -x
# to turn on the debugging messages
debug=0
## Print Usage
if [[ $# -ne 4 ]]
then
print "deploy2_5.1.1.ksh Usage:"
print " deploy2_5.1.1.ksh <environment> <state> <viewpath>
<item>"
fi
## Parameters passed to the script
environment="$1"
state="$2"
viewpath="$3"
item="$4"
## variables used in the script
HARVEST_HOME=`echo ~harvest5`
HARVEST_WORKDIR="${HARVEST_HOME}/workdir"
HARVEST_SCRIPTS="${HARVEST_HOME}/SCRIPTS"
env_nospaces=`print -r ${environment} | sed -e 's/ //g'`
state_nospaces=`print -r ${state} | sed -e 's/ //g'`
if [[ $debug -eq 1 ]] then
print "Inside the deploy2_5.1.1.ksh"
fi
## Get the destination in the filesystem where
## the files are to be copied.
.. ${HARVEST_SCRIPTS}/get_harvest_dest_info.ksh "${environment}" "$
{state}" "${viewpath}" "${item}"
## To find the destination is a directory
if [ -d "${dest_dir}" ]; then
print "The destination is a directory"
. ${HARVEST_SCRIPTS}/deploy_3.ksh "${environment}" "${state}" "$
{viewpath}" "${item}"
## To find the destination is a file
elif [ -f "${dest_dir}" ]; then
print "The destination is a file"
## To check whether the file is empty
if [ wc -l ${dest_dir} -eq 0 ]; then
print "file is empty: It should contain some entrys"
else
dest_dir1=${dest_dir}
cat ${dest_dir1} | \
while IFS = read -r line
do
echo "Found line: $line"
dest_dir=&line
. ${HARVEST_SCRIPTS}/deploy_3.ksh "${environment}" "${state}"
"$
{viewpath}" "${item}"
done
fi
## When a file does not exist copy the file with the same name
else
print "File does not exist"
.. ${HARVEST_SCRIPTS}/deploy_3.ksh "${environment}" "${state}" "$
{viewpath}" "${item}"
fi
.
- Follow-Ups:
- Re: To find wether given entry is a file or directory
- From: Dan Mercer
- Re: To find wether given entry is a file or directory
- From: OldSchool
- Re: To find wether given entry is a file or directory
- Prev by Date: Re: Regarding the usage of basename
- Next by Date: Re: Regarding the usage of basename
- Previous by thread: Re: Regarding the usage of basename
- Next by thread: Re: To find wether given entry is a file or directory
- Index(es):
Relevant Pages
|