Tomcat停止脚本shutdown.sh分析

【广告位】文章头部(标题下方、正文上方)

一、分析说明
    为了写出更加完善的tomcat启动方面的脚本,用于代码上线自动化,特分析下tomcat的bin目录下的shutdown.sh脚本,学习标准的sh脚本的编写方法,从中吸取经验

二、脚本分析
#!/bin/sh


# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# -----------------------------------------------------------------------------
# Stop script for the CATALINA Server
#
# $Id: shutdown.sh 1130937 2011-06-03 08:27:13Z markt $
# -----------------------------------------------------------------------------


# resolve links - $0 may be a softlink
PRG="$0"


while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done
#上面循环语句的意思是保证文件路径不是一个连接,使用循环直至找到文件原地址
#遇到一时看不明白的shell,可以拆解后自己在linux反复运行验证,一点点拆解就会明白的
#link=`expr "$ls" : '.*-> \(.*\)$'` 模拟后: expr 'lrwxrwxrwx 1 root root 19 3月  17 10:12 ./bbb.sh -> /root/shell/test.sh' : '.*-> \(.*\)$'
#很明确的发现是用expr来提取/root/shell/test.sh的内容

【广告位】文章正文中间
本文已展示 50% · 完整内容需验证码解锁

关注公众号,解锁完整文章

微信扫码关注 星哥玩云, 在公众号对话框回复关键词 星哥玩云博客 获取验证码。输入后即可阅读全文, 一次解锁全站文章通用。

星哥玩云 微信公众号二维码
微信扫一扫 / 长按识别,关注「星哥玩云」
【广告位】文章底部(正文结束、评论区上方)
评论功能已在静态化后停用 · 返回顶部 ↑