在Red Hat 7.4的init.d中,我有文件sapabi,该文件是通过调用安装的
这将导致类似/etc/rc3.d /
的条目/etc/rc6.d /
中的示例条目当我以root用户身份执行命令时
一切正常,并且sapcontrol按预期启动或停止了远程SAP诊断代理。
但是,当我输入“ reboot”命令时:
NAME sapcontrol(版本:753,补丁200,更改列表1844229)
简介sapcontrol [-prot] [-trace] [-debug] ...
非常感谢您的帮助
#!/bin/sh
#
# /etc/init.d/sapabi
#
# chkconfig: 345 91 09
# description: Start / stop SAP
#
### BEGIN INIT INFO
# Provides: sapabi
# Required-Start: $network $syslog $local_fs $named $remote_fs $time
# X-UnitedLinux-Should-Start:
# Required-Stop: $network $syslog $local_fs $named $remote_fs $time
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Start the sap system
# Description: Start the sap system
### END INIT INFO
PGM_PATH=$0
ARG1=$1
ARG2=$2
# Remote Diagnostics Agent configuration
#
# DA_R : If set to 1, remote diagnostics services will be started.
#
DA_R=1
DA_R_OS_USER="daaadm"
DA_R_OS_USER_PASSWORD="xxxxxx"
DA_R_INSTANCE_NR="98"
DA_R_START_CMD="StartSystem"
DA_R_STOP_CMD="StopSystem"
DA_R_HOST="xxx.xxx.xxx"
log=/var/log/sapabi.log
function ping_server()
{
target=$1
ping -c1 -w3 ${target} &>/dev/null && return 1 || return 0
}
function start_service()
{
serviceName=$1
localSidAdm=$2
serviceHost=$3
serviceUser=$4
servicePassword=$5
serviceInstance=$6
serviceStartCmd=$7
processName=$8
waitTime=$9
ping_server $serviceHost;
if [ $? -eq 1 ];
then
echo "in ping start_service $serviceName" >> $log
eval ' su -s /bin/csh -l "$localSidAdm" -c "sapcontrol -nr "$serviceInstance" -host "$serviceHost" -user "$serviceUser" "$servicePassword" -function "$serviceStartCmd""' >> $log
test=""
startTime=$(date +%s)
currentTime=$(date +%s)
while [[ "${test}" != *"GREEN"* && ($((currentTime - startTime)) -lt $waitTime) ]];
do
test=`su -s /bin/csh -l "$localSidAdm" -c 'sapcontrol -nr '"$serviceInstance"' -host '"$serviceHost"' -user '"$serviceUser"' '"$servicePassword"' -function GetProcessList | grep '"$processName"''`
# Do not print the trailing newline character
echo -n "."
sleep 1
currentTime=$(date +%s)
done
echo ""
echo "$serviceName - time $((currentTime - startTime)) seconds - ${test}" >> $log
else
echo "Error : ${serviceName} host ${serviceHost} not available"
do_exit ${ERR_unknown_host}
fi
unset serviceName
unset localSidAdm
unset serviceHost
unset serviceUser
unset servicePassword
unset serviceInstance
unset serviceStartCmd
unset processName
unset waitTime
}
start() {
#start the remote Diagnostics Agent
if [ "$DA_R" == 1 ];
then
echo "Starting the remote Diagnostics Agent"
start_service "Remote Diagnostics Agent" $LOCAL_SIDADM $DA_R_HOST $DA_R_OS_USER $DA_R_OS_USER_PASSWORD $DA_R_INSTANCE_NR $DA_R_START_CMD "jstart" "2700"
fi
}
... similar stop functions ...
case "${ARG1}" in
start )
start
;;
stop )
stop
;;
status )
status
;;
restart )
stop
start
;;
* )
echo "Usage: ${PGM_PATH} {start|stop|status|restart}"
do_exit
;;
esac;
答案 0 :(得分:0)
如果我正确阅读了您的代码,则可以使用eval创建一个日志条目。在这种情况下,替换eval巫婆回声“ ...”,并删除除开头和结尾引号外的所有引号。
答案 1 :(得分:0)
该问题与密码包含“#”符号有关。需要通过在“#”符号前加上“ \”来转义。