The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 04-25-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
All of your attempts are very close. As far as I can tell, the last one should have worked -- can you say what error message you get?

Quote:
Example 1:

#!/bin/ksh
file_path=/export/home/orainfodev/sam s
filename="voke.txt"
for file in $file_path; do
[[ -f $filename ]]
pmcmd startworkflow -u Administrator -p SADMIN -s odsdbq1:4001 -f IR_Custom WF_Test_Mapping
done
The -f command is just fine, but you are not using the result for anything. You could wrap that in an "if" or other conditional and it would have worked. Also the file_path needs to be put in double quotes when you declare it. Presumably the file_path paths are directories in which you want to look for voke.txt?

Code:
for file in /export/home/orainfodev/sam s ; do
    if test -f $file/voke.txt; then
        pmcmd startworkflow -u Administrator -p SADMIN -s odsdbq1:4001 -f IR_Custom WF_Test_Mapping
    else
        echo "$0: $file/voke.txt: not found" >&2
    fi
done
(Isn't the workflow command supposed to refer to the file you are checking for also, though? Either by descending into the directory where you found it, or via a command-line parameter.)

Quote:
Example 2:

#!/bin/ksh
if (! -e "/u01/app/informatica/7.1.4/server/TgtFiles/sample.txt")
then
pmcmd startworkflow -u Administrator -p SADMIN -s odsdbq1:4001 -f IR_Custom WF_Test_Mapping
else
echo "Sorry Cannot start the workflow as there is no file existing in the folder"
fi
The parentheses in the "if" are not correct syntax, but again, very close.

Quote:
Example 3:

#!/bin/ksh
filename = "export/home/orainfodev/invoke.txt"
if test -f "$filename" then
echo "file exists"
else
echo "file does not exists"
fi
You need a semicolon before the "then", or put it on a new line. Then this would work. Sheer bad luck you didn't stumble over the solution at this point.

Quote:
Example 4:

#!/bin/ksh
echo "Please enter a file name"
read fname
if test -f "$fname"
then echo "$fname exists"
else
echo "$fname does not exists"
fi
This works for me under bash. Some shells might be picky about requiring new lines after "then" and "else", maybe.