shell函数传参

docker-compose-run

#!/bin/bash

function tips2p() {
    echo "Second parameter please choose one below:"
    echo "`ls  /apps/issoc-config/dcow/ |grep -v $0|grep -v grep`"
}


function start() {
    module_names="`ls  /apps/issoc-config/dcow/ |grep -v $0|grep -v grep`"
    mod=$1
    result=`echo $module_names|grep $mod`
    if [ "${result}" != "" ]; then
     cd  /apps/issoc-config/dcow/$1 && /usr/sbin/docker-compose up -d
     echo "$1: started"
    else
       tips2p
       exit 1
    fi
}

function stop() {
    module_names="`ls  /apps/issoc-config/dcow/ |grep -v $0|grep -v grep`"
    mod=$1
    result=`echo $module_names|grep $mod`
    if [ "${result}" != "" ]; then
     cd  /apps/issoc-config/dcow/$1 && /usr/sbin/docker-compose down
     echo "$1: stopped"
    else
       tips2p
       exit 1
    fi
}

function checkalive() {
  if [ `docker ps | grep $1 |grep -v $0|grep -v grep|wc -l` = 1 ]; then
     echo "$1: alive"
  else
       echo "$1: not alive"
       exit 1
  fi
}


case $1 in
        stop)
            stop $2
            ;;
        start)
            start $2
            ;;
        checkalive)
            checkalive $2
            ;;
        *)
            echo "First parameter please choose one below:"
            echo "stop|start|checkalive"
            exit 1
            ;;
esac

使用:

sh docker-compose-run.sh stop dcow_velocity_acl

注意$1和$2的位置

posted @ 2022-02-24 15:37  豆浆D  阅读(525)  评论(0编辑  收藏  举报