Operating System - HP-UX
1826489 Members
3859 Online
109692 Solutions
New Discussion

Problems with Start up script in HP-UX 11.11

 
jmckinzie
Super Advisor

Problems with Start up script in HP-UX 11.11

I have a problem with a startup script.

I am ultimately su to another user to start a process but, when the script it not taking the value as the variable from the command line.

Any help would be appreciated.

# cat /sbin/init.d/iplanet.sh
#!/sbin/sh
#
# @(#)B.11.11_LR
#
# NOTE: This script is not configurable! Any changes made to this
# script will be overwritten when you upgrade to the next
# release of HP-UX.
#
# WARNING: Changing this script in any way may lead to a system that
# is unbootable. Do not modify this script.

#
# Start/Stop SMARTII Web Application
#

# Allowed exit values:
# 0 = success; causes "OK" to show up in checklist.
# 1 = failure; causes "FAIL" to show up in checklist.
# 2 = skip; causes "N/A" to show up in the checklist.
# Use this value if execution of this script is overridden
# by the use of a control variable, or if this script is not
# appropriate to execute for some other reason.
# 3 = reboot; causes the system to be rebooted after execution.
# 4 = background; causes "BG" to show up in the checklist.
# Use this value if this script starts a process in background mode.

# Input and output:
# stdin is redirected from /dev/null
#
# stdout and stderr are redirected to the /etc/rc.log file
# during checklist mode, or to the console in raw mode.

PATH=/usr/sbin:/usr/bin:/sbin
export PATH

# NOTE: If your script executes in run state 0 or state 1, then /usr might
# not be available. Do not attempt to access commands or files in
# /usr unless your script executes in run state 2 or greater. Other
# file systems typically not mounted until run state 2 include /var
# and /opt.

rval=0

# Check the exit value of a command run by this script. If non-zero, the
# exit code is echoed to the log file and the return value of this script
# is set to indicate failure.

set_return() {
x=$?
if [ $x -ne 0 ]; then
echo "EXIT CODE: $x"
rval=1 # script FAILed
fi
}

# Kill the named process(es).
# $1=

killproc() {
pid=`ps -el | awk '( ($NF ~ /'"$1"'/) && ($4 != mypid) && ($5 != mypid) ){ print $4 }' mypid=$$ `
if [ "X$pid" != "X" ]; then
if kill "$pid"; then
echo "$1 stopped"
else
rval=1
echo "Unable to stop $1"
fi
fi
}


case $1 in
'start_msg')
# Emit a _short_ message relating to running this script with
# the "start" argument; this message appears as part of the checklist.
echo "Starting the SMARTII Web Applications subsystem"
;;

'stop_msg')
# Emit a _short_ message relating to running this script with
# the "stop" argument; this message appears as part of the checklist.
echo "Stopping the SMARTII Web Applications subsystem"
;;

'start')

# source the system configuration variables
if [ -f /etc/rc.config ] ; then
. /etc/rc.config
else
echo "ERROR: /etc/rc.config defaults file MISSING"
fi

# Check to see if this script is allowed to run...
if [ "$CONTROL_VARIABLE" != 1 ]; then
rval=2
else

# Execute the commands to start your subsystem
:
fi
su - smt2unb;. /etc/smt2 SMARTNA_QA;start_iplanet.sh
su - smt2unb;. /etc/smt2 SMARTNA_QA2;start_iplanet.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_IMP;start_iplanet.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_QA;start_iplanet.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_QA2;start_iplanet.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_QA3;start_iplanet.sh
su - smt2unb;. /etc/smt2 SMARTNA_QA;start_xfer.sh
su - smt2unb;. /etc/smt2 SMARTNA_QA2;start_xfer.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_IMP;start_xfer.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_QA;start_xfer.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_QA2;start_xfer.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_QA3;start_xfer.sh
;;

'stop')
# source the system configuration variables
if [ -f /etc/rc.config ] ; then
. /etc/rc.config
else
echo "ERROR: /etc/rc.config defaults file MISSING"
fi

# Check to see if this script is allowed to run...
if [ "$CONTROL_VARIABLE" != 1 ]; then
rval=2
else
:
# Execute the commands to stop your subsystem
su - smt2unb;. /etc/smt2 SMARTNA_QA;stop_xfer.sh
su - smt2unb;. /etc/smt2 SMARTNA_QA2;stop_xfer.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_IMP;stop_xfer.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_QA;stop_xfer.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_QA2;stop_xfer.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_QA3;stop_xfer.sh
su - smt2unb;. /etc/smt2 SMARTNA_QA;stop_iplanet.sh
su - smt2unb;. /etc/smt2 SMARTNA_QA2;stop_iplanet.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_IMP;stop_iplanet.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_QA;stop_iplanet.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_QA2;stop_iplanet.sh
su - smt2ulb;. /etc/smt2 SMARTLAT_QA3;stop_iplanet.sh

fi
;;

*)
echo "usage: $0 {start|stop|start_msg|stop_msg}"
rval=1
;;
esac

exit $rval




# cat /etc/smt2
#
#############################################################################
# Script : smt2.env
# Description : Main script that presents a menu using serv.lst file as
# lookup provided that no parameter is specified.
# In the event a parameter for is specified it is checked
# against serv.lst file and the environment is set.
#
# Usage : . ./smt2.env
#
# Change History
#
# Date Version Developer Description
# ------------ ------- ----------------- ------------------------------------------
# 26-JAN-2006 1.0 Hennie Vermeulen Initial version
#############################################################################
#
function set_env
{
export SMT2_ENV=`cat $SERVERLIST | grep -v "#" | grep -w $DSQUERY |awk -F ":" '{print $3}'|head -n1`
export SMT2_ENV_CTRY=`cat $SERVERLIST | grep -v "#" | grep -w $DSQUERY |awk -F ":" '{print $4}'|head -n1`
export SMT2_HOME=`cat $SERVERLIST | grep -v "#" | grep -w $DSQUERY |awk -F ":" '{print $5}'|head -n1`
export SMT2_VAR_HOME=`cat $SERVERLIST | grep -v "#" | grep -w $DSQUERY |awk -F ":" '{print $6}'|head -n1`
export SMT2_MASTER=`cat $SERVERLIST | grep -v "#" | grep -w $DSQUERY |awk -F ":" '{print $7}'|head -n1`
export SMT2_SHARED=`cat $SERVERLIST | grep -v "#" | grep -w $DSQUERY |awk -F ":" '{print $8}'|head -n1`
export SMT2_BATCH_LOGIN=`cat $SERVERLIST | grep -v "#" | grep -w $DSQUERY |awk -F ":" '{print $9}'|head -n1`
l_dsquery=`echo $DSQUERY |tr '[:upper:]' '[:lower:]'`

if [[ `echo "$l_dsquery" | awk '{print index($1,"_")}'` -gt 0 ]]
then
if [[ -z "$SMT2_ENV" ]]
then
export SMT2_ENV=`echo ${l_dsquery} | awk -F "_" '{print $2}'`
fi
if [[ -z "$SMT2_ENV_CTRY" ]]
then
export SMT2_ENV_CTRY=`echo ${l_dsquery} | awk -F "_" '{print $1}' | cut -c 6-`
fi
fi
if [[ ! -z "$SMT2_ENV" ]]
then
smt2_env=`echo /$SMT2_ENV"`
export SMT2_ENV=$smt2_env
fi

if [[ ! -z "$SMT2_ENV_CTRY" ]]
then
smt2_env_ctry=`echo /${SMT2_ENV_CTRY}`
export SMT2_ENV_CTRY=$smt2_env_ctry
fi

# Dynamicly setup environment, logicals variables and aliases
if [[ -f ${SMT2_HOME}${SMT2_ENV}${SMT2_ENV_CTRY}/sources/logicals/smt2_local.env ]]
then
. ${SMT2_HOME}${SMT2_ENV}${SMT2_ENV_CTRY}/sources/logicals/smt2_local.env
else
printf "File [${SMT2_HOME}${SMT2_ENV}${SMT2_ENV_CTRY}/sources/logicals/smt2_local.env] not found!\n"
fi
return
}

function menu
{
trap '' 2
stty eof ""

while true;do
let counter=0
typeset -L4 part1="||" # padding is done here
typeset -L4 part2="" # padding is done here
typeset -L62 part3="" # padding is done here
typeset -L2 part4="||" # padding is done here
tput clear
printf "\n"
printf "*************************** AVAILABLE SERVERS *****************************\n"
printf "$part1 $part2 $part3 $part4\n"
while read line;do
if [[ `echo $line | cut -c1` != "#" ]]
then
let counter=counter+1
if [[ `echo $line` != "" ]]
then
env_descr=`echo $line | awk -F ":" '{print $1}'`
typeset -L4 part2="${counter})" # padding is done here
typeset -L62 part3="${env_descr}" # padding is done here
printf "$part1 $part2 $part3 $part4\n"
fi
fi
done < $SERVERLIST
typeset -L4 part2="" # padding is done here
typeset -L62 part3="" # padding is done here
printf "$part1 $part2 $part3 $part4\n"
printf "***************************************************************************\n"
printf "Enter Server Number : "
read server
if [[ ! -z $server ]]
then
if [[ ! -n "$( print - "$server" | sed 's/^[+-]//;s/[1-9]//g;s/\.//' )" ]]
then
export DSQUERY=`cat ${SERVERLIST} | grep -v "#" | awk -F ":" '{print $2}' | tail +$server | head -n1`
[[ -n $DSQUERY ]] && break
fi
fi
done
trap 2
stty eof "^D"
return
}
#
# Main
#
export PATH_ORIG=${PATH_ORIG:=$PATH}
export PATH=$PATH_ORIG
# Servers list is located in /etc or home
export SERVERLIST="/etc/smt2_servs.env"
[[ ! -L $SERVERLIST ]] && SERVERLIST="$HOME/smt2_servs.env"
#
# Debug
# if [ $# != 0 ] ; then
# echo "# of Params: $#"
# let i=0
# while [[ $i -le $# ]]; do
# eval echo "Param $i = \$$i"
# let i=i+1
# done
# else
# echo "No Params"
# fi

par1=${1:-""}
if [[ -z $par1 ]]
then
menu
else
par1=`echo $par1 |tr '[:lower:]' '[:upper:]'`
shift $#
export DSQUERY=`cat ${SERVERLIST} | awk -F ":" '{print $2}'|grep -iw $par1 | head -n1`
if [[ ! -n $DSQUERY ]]
then
printf "\nInvalid environment, check '${SERVERLIST}' for a list of valid environments.\n"
printf "USAGE: . ./smt2_menu.sh \n"
[[ $0 != "-ksh" ]] && return 1
fi
fi
set_env
#
# Setup prompt
typeset -x PS1=$LOGNAME@${DSQUERY}:'$PWD >'


Appreciate it.

1 REPLY 1
James R. Ferguson
Acclaimed Contributor

Re: Problems with Start up script in HP-UX 11.11

Hi:

This will not work:

# su - smt2unb;. /etc/smt2 SMARTNA_QA;start_iplanet.sh

You need:

su - smt2unb -c '. /etc/smt2 SMARTNA_QA;start_iplanet.sh'

Regards!

...JRF...