To find wether given entry is a file or directory



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

.



Relevant Pages

  • use of ssh command and to find an entry is a file or directory
    ... I used -d and -f command to check wether it is a directory or file. ... The entry is located on a remote computer. ... Actual script ...
    (comp.unix.shell)
  • Re: To find wether given entry is a file or directory
    ... In this script i have to check whether the dest_dir is a file or ... I used -d and -f command to check wether it is a directory or file. ... The entry is located on a remote computer. ...
    (comp.unix.shell)
  • Re: Shutting down a remote machine.
    ... > remote computer. ... shellexecute to script something like the following command: ...
    (comp.lang.pascal.delphi.misc)
  • Re: Script to copy table between databases
    ... database you have various optios with you. ... With the help of bcp command you can transfer the data to and from the ascii ... Select the objects you wish to script. ... statement becase as you stated "destination table already exists and is ...
    (microsoft.public.sqlserver.mseq)
  • Paste Command
    ... I have a script that has the "ActiveSheet.Paste" command ... When it executes, it leaves the ... message "Select destination and press ENTER or choose ...
    (microsoft.public.excel.programming)