Operating System - HP-UX
1748288 Members
3438 Online
108761 Solutions
New Discussion юеВ

Re: KSH to CSH conversion not working.

 
SOLVED
Go to solution
wayne_104
Regular Advisor

KSH to CSH conversion not working.

Hi I have had to convert a ksh script which works to a csh script.

the converted script is as below.

#!/usr/bin/csh
set +u
# Generic Start and stop for HP cluster Oracle DB's
# Parameters are $1 function ... $2 DB Name
#
# First validate user is oratst
clear
set ck_user=`id | tr '(' " " | tr ')' " " | awk '{print $2}'`
if ($ck_user != 'oratst' ) then
echo 'ONLY user oratst can run this function ... '$ck_user
echo '____________________________________'
echo '\nFirst login as oratst then try again '
sleep 2
#endif
#end
# Start or Stop function
case $1 in
start) set DBFUNCTION='startup'
set LSNFUNCTION='start';;
stop) set DBFUNCTION='shutdown immediate'
set LSNFUNCTION='stop';;
*) echo 'Usage is .......... start or stop DB Name '
exit;;
esac
#Define DB and listener
case $2 in
TST) set DBNAME='TST';set DB_LISTENER='TST';;
#smst) DBNAME='smst';DB_LISTENER='smst';;
#medp_dba) DBNAME='medp';DB_LISTENER='medp_dba';;
*) echo 'only IALCH Databases smsm allowed'
exit;;
esac

ORACLE_SID=$DBNAME; export ORACLE_SID
echo 'Starting Listener now '
/oracle/TST/102_64/bin/lsnrctl $LSNFUNCTION listener_${DB_LISTENER}

sqlplus -s /nolog <connect / as sysdba
$DBFUNCTION
EOF
# End of script


However i keep getting the error ./start_stop_SAPoraDB.sh[9]: Syntax error at line 9 : `if' is not matched.

so i made a simpler script.

#!/bin/csh
if ($#argv == 0) then
echo "Proc arg missing"
endif

and i get the error ./test2[2]: Syntax error at line 2 : `if' is not matched.

why is this happening?
I have type csh and also su to the csh user with the same results.
8 REPLIES 8
Jose Mosquera
Honored Contributor

Re: KSH to CSH conversion not working.

Hi,

I'm seeing that your "if ($ck_user != 'oratst' )" sentence has no corresponding endif, in your case is comment.

Rgds.
wayne_104
Regular Advisor

Re: KSH to CSH conversion not working.

yea in desperation i commented it out.

But same is happening with second script.
James R. Ferguson
Acclaimed Contributor

Re: KSH to CSH conversion not working.

Hi Wayne:

You need to look at the Korn/Posix syntax. A quick resource is this:

http://docs.hp.com/en/B2355-90046/index.html

Here is a more formatted, Korn or Posix script:

#!/usr/bin/sh
set +u
# Generic Start and stop for HP cluster Oracle DB's
# Parameters are $1 function ... $2 DB Name
#
# First validate user is oratst
clear
ck_user=$(id | tr '(' " " | tr ')' " " | awk '{print $2}')
if [ "$ck_user" != 'oratst' ]; then
echo "ONLY user oratst can run this function ... $ck_user"
echo "____________________________________"
echo "\nFirst login as oratst then try again "
sleep 2
fi
#
# Start or Stop function
case $1 in
start) DBFUNCTION='startup'
LSNFUNCTION='start'
;;
stop ) DBFUNCTION='shutdown immediate'
LSNFUNCTION='stop'
;;
* ) echo 'Usage is .......... start or stop DB Name '
exit
;;
esac
#Define DB and listener
case $2 in
TST ) DBNAME='TST'
DB_LISTENER='TST'
;;
# smst ) DBNAME='smst'
# DB_LISTENER='smst'
# ;;
# medp_dba)
# DBNAME='medp'
# DB_LISTENER='medp_dba'
# ;;
* ) echo 'only IALCH Databases smsm allowed'
exit
;;
esac
export ORACLE_SID=$DBNAME
echo 'Starting Listener now '
/oracle/TST/102_64/bin/lsnrctl $LSNFUNCTION listener_${DB_LISTENER}
sqlplus -s /nolog <connect / as sysdba
$DBFUNCTION
EOF
# End of script

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor
Solution

Re: KSH to CSH conversion not working.

Hi (again) Wayne:

Well that was stupid, on my part :-( You are trying to convert a working 'ksh' script to 'csh' not the other way around!

First, why do you want to do this? No matter what your default shell is, you can run scripts in any language.

Second, you are trading a fairly robust shell ('ksh') for a broken, dysfunctional one in the form of 'csh'. The C-shell is fine for very simple scripts and that's about all. I urge you to read:

http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/

Regards!

...JRF...

wayne_104
Regular Advisor

Re: KSH to CSH conversion not working.

Hi Because the damn sap consultant that get paid more than me said that is the shell that sap prefers.
wayne_104
Regular Advisor

Re: KSH to CSH conversion not working.

I have solved the problem.

I usermod the sap user to ksh and my original script runs like a charm.

Found a posting on the web that ksh is prefered to csh so sap consultant now has to explain.

Dennis Handly
Acclaimed Contributor

Re: KSH to CSH conversion not working.

>I usermod the sap user to ksh and my original script runs like a charm.

As JRF said, you don't have to convert the user, just individual scripts.
The #! line determines the shell as long as it is executable.

Re: KSH to CSH conversion not working.

Well the SAP consultant will probably reference SAP Note 202227, which does indeed recommend the csh shell as the login shell - you would have to ask SAP why they do this given the well-known issues with csh. The note talks about some issues with different implementations of ksh on different platforms, but to be honest I've never seen any serious issues with using ksh or even sh (the POSIX shell on HP-UX, not the bourne shell) with SAP.

That said, this is a recommendation for the _login_ shell, not for what shell you write scripts in. As others have already indicated, you can still have csh as the login shell and then write scripts in ksh/sh as long as you have the appropriate #! entry on the first line of the script.

HTH

Duncan

I am an HPE Employee
Accept or Kudo