gpt4 book ai didi

bash - RETVAL 是什么意思?

转载 作者:行者123 更新时间:2023-11-29 08:53:38 27 4
gpt4 key购买 nike

我正在尝试为 startstop 服务的脚本创建一个模板。我正在检查 tomcat 启动和停止的模板并查看命令 RETVAL=$?

这是做什么的?我应该保留它吗?顺便说一句,我的脚本在下面,以防你们想看。

#!/bin/bash
#===================================================================================
#
#
FILE: <script-file-name>.sh
#
#
USAGE: <script-file-name>.sh [-d] [-l] [-oD logfile] [-h] [starting directories]
#
# DESCRIPTION: List and/or delete all stale links in directory trees.
#
The default starting directory is the current directory.
#
Don’t descend directories on other filesystems.
#
#
OPTIONS: see function ’usage’ below
# REQUIREMENTS: ---
#
BUGS: ---
#
NOTES: ---
#
AUTHOR: Valter Henrique, valter.henrique@<company>.com
#
COMPANY: <company>
#
VERSION: 1.0
#
CREATED: 03.14.13
#
REVISION: 03.14.13
#===================================================================================
#
# chkconfig: 345 90 12
# description: <service-name> start, stop, restart service
#
# Get function from functions library
. /etc/init.d/functions

folder=/<company>/<service-folder> #folder to the application
service="<service-name>" #name of the service

startup=$folder/start.sh
shutdown=$folder/stop.sh


#=== FUNCTION ================================================================
#
NAME: start
# DESCRIPTION: Start the service <service-name>
# PARAMETER 1: ---
#===============================================================================
start() {

#----------------------------------------------------------------------
# logging the start
#----------------------------------------------------------------------
initlog -c "echo -n Starting $service:"

#----------------------------------------------------------------------
# getting the process PID
#----------------------------------------------------------------------
pid_process=`ps -ef | grep "$folder/<jar>.jar" | grep -v grep |awk -F' ' '{ print $2 }'`;

if [ $pid_process ]; then
echo "<service-name> is running!"
echo "Stop then first!"
else
action $"Starting <service-name> service: " su - <user_deployer> -c $startup
RETVAL=$?
fi
#----------------------------------------------------------------------
# create the lock file
#----------------------------------------------------------------------
touch /var/lock/subsys/$service
success $"Sucess $service startup"
echo
}

#=== FUNCTION ================================================================
#
NAME: stop
# DESCRIPTION: Stop the service <service-name>
# PARAMETER 1: ---
#===============================================================================
stop() {
#----------------------------------------------------------------------
# logging the stop
#----------------------------------------------------------------------
initlog -c "echo -n Stopping $service: "
killproc $service
#----------------------------------------------------------------------
# now, delete the lock file
#----------------------------------------------------------------------
rm -f /var/lock/subsys/$service
echo
}

#----------------------------------------------------------------------
# Main Logic
#----------------------------------------------------------------------
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $service
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0

最佳答案

$? 给出最后执行的命令的状态。在您的例子中,最后执行的命令是 action.... 。此命令的退出状态将出现在 $? 中,稍后将在 RETVAL 变量中捕获。 如果命令成功,$? 将包含 0,否则为非零值。

关于bash - RETVAL 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15411429/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com