如何从bash执行ksh脚本

时间:2018-09-17 05:02:58

标签: bash shell ksh

我目前有一个调用另一个ksh脚本的ksh脚本。需要在ksh shell用户的上下文中从bash shell调用“父” ksh脚本。尝试以下操作会返回此错误消息

以root用户身份进入bash shell

su - whics -c '/usr/bin/nohup /whics/t99/wv.4gm/wv99b.4gs/wv99b.sh -s 1 -m u -sleep 5 > ./nohup.out &'

/whics/t99/wv.4gm/wv99b.4gs/wv99b.sh [8]:。: wh_setENV.sh:无法打开[无此类文件或目录]

wh_setENV.sh 实际上位于/ whics / t99 / bin

但是,按顺序运行以下命令时,不会出现此错误

server:~ su - whics

server:/whics/t99 cd ./wv.4gm/wv99b.4gs

server:/whics/t99/wv.4gm/wv99b.4gs nohup ./wv99b.sh -s 1 -m u -sleep 5 &

server:/whics/t99/wv.4gm/wv99b.4gs nohup: ignoring input and appending output to `/home/whics/nohup.out'

[1] +  Done                    nohup ./wv99b.sh -s 1 -m u -sleep 5 &

server:/whics/t99/wv.4gm/wv99b.4gs cat /home/whics/nohup.out Mon Sep 17 12:27:40 AEST 2018 : Start wv99b

wv99b.sh

#!/bin/ksh
# Copyright (C) 1992-1997 Wacher Pty. Limited
# Sccsid: %Z% %M%%Y% %Q%%I% %E%
myname=${0##*/}     # a useful identifying variable
mydir=${0%$myname}      # where this script is
vSFX=${myname##*.}

. wh_setENV.sh # P4813 - when using 4js:WebServices, the $fglidir/lib in LD_LIBRARY_PATH causes problems

test $debugxv && set -xv

#--------------------------------------------------------------------------------------------------------------------------------------#
wv99b_msg() {
vERR="`date` : ${vMSG}"
echo $vERR | tee -a ${vLOG}
}
#--------------------------------------------------------------------------------------------------------------------------------------#
wv99b_sysFragments() {

vSYSFRAGOK="0"
vSYSFRAGMENTS="${vTABNAME}.sysfrags.unl" ; rm -f $vSYSFRAGMENTS
$WH_ISQL $company - <<! 2>/dev/null | sed "/exprtext/d;/^$/d;s/ //g;s/[()]//g" |cut -f1 -d'=' >| ${vSYSFRAGMENTS}
select F.exprtext 
from systables S, sysfragments F
where S.tabid   > 99
and   S.tabtype = "T"
and   S.tabname = "${vTABNAME}"
and   S.tabid   = F.tabid
and   S.tabtype = F.fragtype
and   F.evalpos = 0
;
!

if  [ -s ${vSYSFRAGMENTS} ] ; then
    # search for the vCOLUMN in the vSYSFRAGMENTS output
    vSYSFRAGOK=`grep -i ${vKEY} ${vSYSFRAGMENTS} 2>/dev/null | wc -l | awk '{print $1}'`
else
    vSYSFRAGOK="0"
    rm -f ${vSYSFRAGMENTS}   # cleanup
fi

}
# MAIN #
vARGS="$@"
vHERE=`pwd`
vLOG="${vHERE}/errlog"

vD=0           # debug indicator
vI=0           # infile indicator
vQ=0           # email indicator
vM=0           # mode indicator
vS=0           # serial indicator
vNO_MULTI=0    # default to false
vNO_PROGI=0    # default to false
vTABLE=0       # default to 0
vSLEEP=5       # default to 0

for i in $vARGS
do
case "$i" in
       -debug) vD=$2          ;;
      -infile) vI=$2          ;;
       -table) vTABLE=$2      ;;
       -sleep) vSLEEP=$2      ;;
    -no_multi) vNO_MULTI=$2   ;;
    -no_progi) vNO_PROGI=$2   ;;
           -m) vM=$2          ;;
           -q) vQ=$2          ;;
           -s) vS=$2          ;;
esac
shift

done

[[ ${vS} -eq 0 ]] && vMSG="-s parameter not supplied" && wv99b_msg && exit 1

vHERE=`pwd`

if  [ ${vD} -eq 1 ] ; then
    vDEBUG=" -debug 1"
else
    vDEBUG=""
fi

if  [ ${vI} -eq 0 ] ; then
    vINFILE="wv99b.in"
else
    vINFILE="${vI}"
fi

# INIT
vWVI="wv99b_I"   # the name of the (I)dentify script
vWVIS="${vWVI}_${vS}"   # the name of the (I)dentify script PLUS SERIAL
vWVIO="${vWVIS}.unl"   # the name of the (I)dentify script

rm -f ${vWVIO}

# Check that transaction-logging is off

# check that vINFILE exists
if  [ ! -s "${vINFILE}" ] ; then
    vMSG="Error cannot read input file $vINFILE" ; wv99b_msg ; exit 1
fi

# Process only one(1) table
if  [ ${vTABLE} != "0" ] ; then
    vTABLE_FILTER=" -table ${vTABLE} "
else
    vTABLE_FILTER=""
fi

# We need to check if we are running client/server
#
vDB=`echo $company | awk 'BEGIN {FS="@" } { print $1 }'`
vDBSRV=`echo $company | awk 'BEGIN {FS="@" } { print $2 }'`

case X${vDBSRV}X in
  XX) vREMOTE_DB="" ;;
   *) vREMOTE_DB=" -db ${vDB}  -dbsrv ${vDBSRV} " ;;
esac
#_end

vMSG="Start  wv99b" ; wv99b_msg

因此在wv99b.sh文件中,我更改了

. wh_setENV.sh
to
. /whics/t99/bin/wh_setENV.sh

但是,现在我得到了错误 无法读取输入文件wv99b.in

我检查了wv99b.in,它与'wv99b.sh'位于同一目录(即/whics/t99/wv.4gm/wv99b.4gs/)

wh_setENV.sh

#!/usr/bin/ksh

test $debugxv && set -xv

trap door 1 2 3 5 9 15

#---------------------------------------------------------------------#
door() {
    echo "`date` ERROR($?) occured in $0" >> $WH/batch.4gm/trap.log
} #end door
#---------------------------------------------------------------------#

# Script to set Environment variables for various scripts

# Stef

# Unix specific


umask 002

: ${WH:="/whics/prod"}

set -a
TERM=xterm
vHERE=`pwd`
TERMCAP=$WH/etc/termcap
vHOST=`hostname | cut -f1 -d'.'`
set +a

#LD_LIBRARY_PATH="$WH/lib.4gm/S_lib:$fglibdir/S_lib"    # GUC R481
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$INFORMIXDIR/lib/c++:$INFORMIXDIR/lib/cli:$INFORMIXDIR/lib/client:$INFORMIXDIR/lib/csm:$INFORMIXDIR/lib/dmi"

LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql:$INFORMIXDIR/lib/tools.$CCODE" 

export LD_LIBRARY_PATH

# EOF #

1 个答案:

答案 0 :(得分:0)

更新:OP修改/更新了问题之后...

    wv99b.in中引用了
  • wv99b.sh
  • 您没有提供wv99b.in的路径,所以...
  • 如果您从wv99b.sh以外的某个目录调用/whics/t99/wv.4gm/wv99b.4gs ...
  • 运行测试[ ! -s "${vINFILE}" ]时,脚本(正确)确定"${vINFILE}"不在您从中调用wv99b.sh的目录中

最终结果... sh_setENV.sh的原始问题已得到解决,但现在wv99b.in发生了完全相同的问题,此处需要相同的解决方案...调用wv99b.sh从其主目录或提供wv99b.in的完整路径。


原始帖子:

扩展Andre的评论...

wv99b.sh中,您有以下一行:

. wh_setENV.sh

这将在调用wh_setENV.sh的目录中查找wv99b.sh

在您的原始示例中,您提供了wv99b.sh的完整路径,但是问题是... 调用从哪个目录?我们可以从错误中分辨出来...

wh_setENV.sh: cannot open [No such file or directory]

...未从wv99b.sh调用/whics/t99/wv.4gm/wv99b.4gs,否则将发现wh_setENV.sh

在第二个示例中,看来wh_setENV.sh的完整路径是:/whics/t99/wv.4gm/wv99b.4gs/wh_setENV.sh,所以您有两个选择:

  • 在最初的示例中,请确保在执行cd /whics/t99/wv.4gm/wv99b.4gs之前先wv99b.4gs

  • 更新wv99b.4gs以包括指向sh_setENV.sh的位置的完整路径,例如:

    . /whics/t99/wv.4gm/wv99b.4gs/wh_setENV.sh