socool111
socool111

Reputation: 1

Calling a both Shell Script and a Korn script in a Korn Script

I am trying to call both a korn shell and a shell script at the same time. In a ksh. My ksh script is as follows:

#!/bin/sh

. /u01/EPM/hyp_app/scripts/maxl/Start_Stop/Stop_All.ksh
. /app/Oracle/Middleware/user_projects/epmsystem1/bin/stop.sh 

This will successfully run the .sh, but will unsuccessfully run the .ksh, and return this error

/u01/EPM/hyp_app/scripts/maxl/Start_Stop/Stop_All.ksh: line 33: syntax error near unexpected token `;'
/u01/EPM/hyp_app/scripts/maxl/Start_Stop/Stop_All.ksh: line 33: `if [ $f1 != ' ' ]; then;'

But when running that Stop_All.ksh by itself, it works fine with no issues.

Why is it a syntax error when run from someplace else, but not a syntax error when run directly? Note the location of this bigger ksh is in the same location as the Stop_All.ksh. So it's not a relative directory issue (i don't think).

Edit:

Part of the problem is that the text files in the Stop_All.ksh are not being create when run as part of the greater script (but creates it no problem when I run it by itself).

#Clears database log
echo ' ' > /u01/EPM/hyp_app/logs/Start_Stop/DatabaseList.log

# run filter export process
$ESS_ENV_DIR/startMaxl.sh $SCRIPT_DIR/maxl/Start_Stop/SpoolDatabase.mxl

echo ' ' > /u01/EPM/hyp_app/export/Start_Stop/Application_List.txt

# Parses it out in do 8 for start and stop, and insert | pipe
sed -i -e 's/./&|/21' -i -e 's/./&|/30' -i -e 's/./&|/40'  /u01/EPM/hyp_app/logs/Start_Stop/DatabaseList.log;
cat /u01/EPM/hyp_app/logs/Start_Stop/DatabaseList.log | grep 'TRUE' > /u01/EPM/hyp_app/export/Start_Stop/GrepApplication_List.txt
while IFS='|' read -r f1 f2 f3 f4 #f5
do echo $f1 $f2 >> /u01/EPM/hyp_app/export/Start_Stop/Application_List.txt
echo $f3 >> /u01/EPM/hyp_app/export/Start_Stop/Application_List.txt

# finishes do while and the points the input file that the IFS reads through (PUT DATABSE TXT FILE HERE)
done < /u01/EPM/hyp_app/export/Start_Stop/GrepApplication_List.txt;
while IFS=' ' read -r f1 f2 f3 f4 #f5
do 

 if [ $f1 != ' ' ]; then;
   $ESS_ENV_DIR/startMaxl.sh $SCRIPT_DIR/maxl/Start_Stop/Master_Stop.mxl $f1 $f2
    fi

Upvotes: 0

Views: 102

Answers (2)

socool111
socool111

Reputation: 1

Thanks to user Nick Burns,

I had to change the top to #!/bin/ksh

Upvotes: 0

Walter A
Walter A

Reputation: 19982

When you test if [ $f1 != ' ' ]; you are expecting that f1 can be a space. Suppose f1 is filled with a space. The line if [ != ' ' ]; is an error.
I think that when you were running Stop_All.ksh by itself, f1 was filled with something else than a space.
Change your code into

if [ "$f1" != ' ' ];

or get used to the syntax with curly braces

if [ "${f1}" != ' ' ];

Upvotes: 1

Related Questions