欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

從一個(gè)linux腳本中學(xué)習(xí)bashshell

以下是一個(gè)resin啟動(dòng)腳本,其中可以學(xué)到很多bash shell的知識(shí)點(diǎn)


#!/bin/sh                   // bash shell腳本
#
# Linux startup script for Resin   //#注釋
# chkconfig: 345 85 15
# description: Resin is a Java Web server.
# processname: wrapper.pl
#
# To install, configure this file as needed and copy init.resin
# to /etc/rc.d/init.d as resin. Then use "# /sbin/chkconfig resin reset"
#
JAVA_HOME=/usr/local/java/jdk    // =號(hào)賦值
RESIN_HOME=/usr/local/resin


export JAVA_HOME RESIN_HOME    // export 定義全局變量


JAVA=$JAVA_HOME/bin/java       // $ 代表變量
#
# If you want to start the entire Resin process as a different user,
# set this to the user name. If you need to bind to a protected port,
# e.g. port 80, you can't use USER, but will need to use bin/resin.
#
USER=
#
# Set to the server id to start
#
#SERVER="-server app-a"
#
ARGS="-resin-home $RESIN_HOME $SERVER"


if test -r /lib/lsb/init-functions; then   // 判斷語(yǔ)句     test -r /lib/lsb/init-functions 條件文件存在并可讀
. /lib/lsb/init-functions                  // . 代表源 同source /lib/lsb/init-functions
else                                       //如果不符合上面的條件


log_daemon_msg () {                     //函數(shù)
      if [ -z "$1" ]; then                 // -z "$1" 變量$1長(zhǎng)度為0   // $1 腳本執(zhí)行時(shí)傳過(guò)來(lái)的第一個(gè)參數(shù)
          return 1                       //返回
      fi


      if [ -z "$2" ]; then
          echo -n "$1:"              // -n 參數(shù) 輸出不換行
          return
      fi
   
      echo -n "$1: $2"
}


log_end_msg () {
      [ -z "$1" ] && return 1    // [ -z "$1" ]為真,執(zhí)行 return 1  


      if [ $1 -eq 0 ]; then       //比較,-eq等于
        echo " ."
      else
        echo " failed!"
      fi
   
    return $1
}


fi


case "$1" in                 //case 選擇語(yǔ)句
start)                     //腳本第一個(gè)參數(shù)為start
log_daemon_msg "Starting resin"    //調(diào)用函數(shù),傳遞參數(shù)
if test -n "$USER"; then           //條件:變量USER長(zhǎng)度不為0
   su $USER -c "$JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS start" 1>/dev/null 2>/dev/null  //su 以其它用戶執(zhí)行 -c執(zhí)行命令后恢復(fù)身份
else
   $JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS start 1>/dev/null 2>/dev/null     //1>dev/null 執(zhí)行正常信息輸出到空文件 2>錯(cuò)誤信息
        fi
log_end_msg $?      // $? 上一條命令執(zhí)行的結(jié)果 0表示成功,更多請(qǐng)查看其它文章
;;
stop)
log_daemon_msg "Stopping resin"
if test -n "$USER"; then
   su $USER -c "$JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS stop" 1>/dev/null 2>/dev/null
else
   $JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS stop 1>/dev/null 2>/dev/null
        fi
log_end_msg $?
;;
restart)
$0 stop       //$0 本腳本名
$0 start
;;
*)                  //除start stop restart外
echo "Usage: $0 {start|stop|restart}"
exit 1  //1表示有錯(cuò)誤
esac


exit 0  //0表示沒(méi)有錯(cuò)誤
 


新聞名稱:從一個(gè)linux腳本中學(xué)習(xí)bashshell
URL鏈接:http://chinadenli.net/article42/pgpchc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google網(wǎng)站設(shè)計(jì)公司商城網(wǎng)站軟件開(kāi)發(fā)面包屑導(dǎo)航網(wǎng)站維護(hù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司