我的shell記錄

我的shell記錄

##!/bin/bash
# addJar.sh
#在已有的jar包中添加新的依賴jar包
path=BOOT-INF/lib
jarName=$1

if [ "$1" = "" ];
then
    echo -e "未輸入替換包名,程序退出!!!"
    exit 1
fi


cd bak
rm -rf *
cp ../*springboot-1.0.0-SNAPSHOT.jar ./
for files in $(ls)
do
  file=${files%\.*}
  
  echo "創建文件夾:${file}"
  mkdir -m 750 ${file}
  echo "移動文件${files}${file}中"
  mv ${files} $file
  echo "解壓jar包"
  cd $file
  jar xf $files
  echo "刪除${files}包"
  rm $files
  ls
  echo "Copy新包至目標路徑下"
  echo "此刻路徑: $(pwd)"
  cp ../../$jarName $path
  jar cf0M $files *
  echo "將新包移動至 $(pwd) ../../"
  mv $files ../../
  echo "此刻路徑: $(pwd)"
  cd ../
  echo "此刻路徑: $(pwd)"
  echo "完成${files}的添加!!!"
  echo ""
  echo ""

done
##!/bin/bash
#replaceJar.sh
#替換jar包
path=BOOT-INF/lib
jarName=$1

if [ "$1" = "" ];
then
    echo -e "未輸入替換包名,程序退出!!!"
    exit 1
fi

if [ ! -d "bak" ];then
   mkdir -m 750 bak
fi

cd bak
rm -rf *
cp ../*springboot-1.0.0-SNAPSHOT.jar ./
for files in $(ls)
  do
    file=${files%\.*}

    echo "創建文件夾:${file}"
    mkdir -m 750 ${file}
    echo "移動文件${files}${file}中"
    mv ${files} $file
    echo "解壓jar包"
    cd $file
    jar xf $files
    echo "刪除${files}包"
    rm $files
    echo "刪除目標包 ${jarName}"
    rm $path/$jarName
    ls
    echo "Copy新包至目標路徑下"
    echo "此刻路徑: $(pwd)"
    cp ../../$jarName $path
    jar cf0M $files *
    echo "將新包移動至 $(pwd) ../../"
    mv $files ../../
    echo "此刻路徑: $(pwd)"
    cd ../
    echo "此刻路徑: $(pwd)"
    echo "完成${files}的替換!!!"
    echo ""
    echo ""

  done
##!/bin/bash
# addOrReplaceFileToConfig.sh
#在已有的jar包中添加替換新的文件
path=BOOT-INF/lib
fileName=$1

if [ "$1" = "" ];
then
    echo -e "未輸入添加的文件名,程序退出!!!"
    exit 1
fi


if [ ! -d "bak" ];then
   mkdir -m 750 bak
fi

cd bak
rm -rf *
cp ../*springboot-1.0.0-SNAPSHOT.jar ./
for files in $(ls)
do
  file=${files%\.*}

  echo "創建文件夾:${file}"
  mkdir -m 750 ${file}
  echo "移動文件${files}${file}中"
  mv ${files} $file
  echo "解壓jar包"
  cd $file
    jar xf $files
    echo "刪除原 ${files} 包"
    rm $files
    echo "進入 $path 中"
    cd $path
      mkdir -m 750 bak
      cd bak
        mv ../*-config-1.0.0-SNAPSHOT.jar ./
        jarName=$(ls *.jar)
        jar xf *-config-1.0.0-SNAPSHOT.jar
        echo "複製文件至 bak中 "
        echo "此刻路徑: $(pwd)"
        rm my-logback-spring.xml
        cp ../../../../../$fileName ./
        rm *-config-1.0.0-SNAPSHOT.jar
        jar cf0M $jarName *
        mv $jarName ../
      cd ../
      rm -rf bak
    cd ../../
    echo "此刻路徑: $(pwd)"
    jar cf0M $files *
    echo "將新包移動至 $(pwd) ../../"
    mv $files ../../
    echo "此刻路徑: $(pwd)"
  cd ../
  echo "此刻路徑: $(pwd)"
  echo "完成${files}$fileName 文件的添加!!!"
  echo ""

done

echo ""
echo "刪除bak文件夾"
cd ../
rm -rf bak
#!/bin/bash
# addWordsToyml.sh
#在已有的jar包中 對yml文件進行添加 詞的動作
path=BOOT-INF/lib

if [ ! -d "bak" ];then
   mkdir -m 750 bak
fi

cd bak
rm -rf *
cp ../*springboot-1.0.0-SNAPSHOT.jar ./
for files in $(ls)
do
  file=${files%\.*}

  echo "創建文件夾:${file}"
  mkdir -m 750 ${file}
  echo "移動文件${files}${file}中"
  mv ${files} $file
  echo "解壓jar包"
  cd $file
    jar xf $files
    echo "刪除原 ${files} 包"
    rm $files
    echo "進入 $path 中"
    cd $path
      mkdir -m 750 bak
      cd bak
        mv ../*-config-1.0.0-SNAPSHOT.jar ./
        jarName=$(ls *.jar)
        jar xf *-config-1.0.0-SNAPSHOT.jar
        sed -i '/logging/a\  config: classpath:my-logback-spring.xml' application-pre.yml
        sed -i 's/
//g' application-pre.yml
        rm *-config-1.0.0-SNAPSHOT.jar
        jar cf0M $jarName *
        mv $jarName ../
      cd ../
      rm -rf bak
    cd ../../
    echo "此刻路徑: $(pwd)"
    jar cf0M $files *
    echo "將新包移動至 $(pwd) ../../"
    mv $files ../../
    echo "此刻路徑: $(pwd)"
  cd ../
  echo "此刻路徑: $(pwd)"
  echo "完成${files}中 yml 文件關鍵詞的添加!!!"
  echo ""
  echo ""

done
#!/bin/bash
#mdir.sh
#批量創建文件夾
echo "開始時間:"`date "+%Y-%m-%d %H:%M:%S"`

/usr/bin/expect -c "

spawn ssh -f -o StrictHostKeyChecking=no [email protected] mkdir -p /app/tomcat/scms/easyloan/afterloan
  expect {
    \"(yes/no)?\" { send \"yes\r\";exp_continue }
    \"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}

spawn ssh -f -o StrictHostKeyChecking=no [email protected] mkdir -p /app/tomcat/scms/easyloan/afterloan
  expect {
    \"(yes/no)?\" { send \"yes\r\";exp_continue }
    \"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}

spawn ssh -f -o StrictHostKeyChecking=no [email protected] mkdir -p /app/tomcat/scms/easyloan/archives
  expect {
    \"(yes/no)?\" { send \"yes\r\";exp_continue }
    \"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}

spawn ssh -f -o StrictHostKeyChecking=no [email protected] mkdir -p /app/tomcat/scms/easyloan/archives
  expect {
    \"(yes/no)?\" { send \"yes\r\";exp_continue }
    \"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}

spawn ssh -f -o StrictHostKeyChecking=no [email protected] mkdir -p /app/tomcat/scms/easyloan/badassets
  expect {
    \"(yes/no)?\" { send \"yes\r\";exp_continue }
    \"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}

spawn ssh -f -o StrictHostKeyChecking=no [email protected] mkdir -p /app/tomcat/scms/easyloan/badassets
  expect {
    \"(yes/no)?\" { send \"yes\r\";exp_continue }
    \"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}

spawn ssh -f -o StrictHostKeyChecking=no [email protected] mkdir -p /app/tomcat/scms/easyloan/classify
  expect {
    \"(yes/no)?\" { send \"yes\r\";exp_continue }
    \"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}

spawn ssh -f -o StrictHostKeyChecking=no [email protected] mkdir -p /app/tomcat/scms/easyloan/classify
  expect {
    \"(yes/no)?\" { send \"yes\r\";exp_continue }
    \"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}

spawn ssh -f -o StrictHostKeyChecking=no [email protected] mkdir -p /app/tomcat/scms/easyloan/credit
  expect {
    \"(yes/no)?\" { send \"yes\r\";exp_continue }
    \"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}

spawn ssh -f -o StrictHostKeyChecking=no [email protected] mkdir -p /app/tomcat/scms/easyloan/credit
  expect {
    \"(yes/no)?\" { send \"yes\r\";exp_continue }
    \"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}

spawn ssh -f -o StrictHostKeyChecking=no [email protected] mkdir -p /app/tomcat/scms/easyloan/customer
  expect {
    \"(yes/no)?\" { send \"yes\r\";exp_continue }
    \"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}

spawn ssh -f -o StrictHostKeyChecking=no [email protected] mkdir -p /app/tomcat/scms/easyloan/customer
  expect {
    \"(yes/no)?\" { send \"yes\r\";exp_continue }
    \"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}

spawn ssh -f -o StrictHostKeyChecking=no [email protected] mkdir -p /app/tomcat/scms/easyloan/loan
  expect {
    \"(yes/no)?\" { send \"yes\r\";exp_continue }
    \"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}

spawn ssh -f -o StrictHostKeyChecking=no [email protected] mkdir -p /app/tomcat/scms/easyloan/loan
  expect {
    \"(yes/no)?\" { send \"yes\r\";exp_continue }
    \"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}



"

echo "結束時間:"`date "+%Y-%m-%d %H:%M:%S"`
#!/bin/bash
#replaceWordsYml.sh
# 對yml中的 關鍵詞進行替換
path=BOOT-INF/lib
key1=$1
key2=$2

if [ "$1" = "" ];
then
    echo -e "請輸入目標關鍵詞!!!"
    exit 1
fi

if [ "$2" = "" ];
then
    echo -e "請輸入替換詞!!!"
    exit 1
fi


if [ ! -d "bak" ];then
   mkdir -m 750 bak
fi

cd bak
rm -rf *
cp ../*springboot-1.0.0-SNAPSHOT.jar ./
for files in $(ls)
do
  file=${files%\.*}

  echo "創建文件夾:${file}"
  mkdir -m 750 ${file}
  echo "移動文件${files}${file}中"
  mv ${files} $file
  echo "解壓jar包"
  cd $file
    jar xf $files
    echo "刪除原 ${files} 包"
    rm $files
    echo "進入 $path 中"
    cd $path
      mkdir -m 750 bak
      cd bak
        mv ../*-config-1.0.0-SNAPSHOT.jar ./
        jarName=$(ls *.jar)
        jar xf *-config-1.0.0-SNAPSHOT.jar
        sed -i "s/$key1/$key2/g" application-pre.yml
        rm *-config-1.0.0-SNAPSHOT.jar
        jar cf0M $jarName *
        mv $jarName ../
      cd ../
      rm -rf bak
    cd ../../
    echo "此刻路徑: $(pwd)"
    jar cf0M $files *
    echo "將新包移動至 $(pwd) ../../"
    mv $files ../../
    echo "此刻路徑: $(pwd)"
  cd ../
  echo "此刻路徑: $(pwd)"
  echo "完成${files}中 yml 文件關鍵詞的替換!!!"
  echo ""
  echo ""

done
#!/bin/bash
#startall.sh
#調用spring-boot.sh
# 當 $1 輸入爲 dr 時 啓動備庫

appCount=`(ls *-springboot-1.0.0-SNAPSHOT.jar | wc -l)`
echo "檢測到【${appCount}】個系統服務"
if [ $appCount -gt 0 ];then
  for appTName in $(ls *-springboot-1.0.0-SNAPSHOT.jar)
  do
    #echo "appTName is ${appTName} "
    appName="${appTName%%-*}"
    echo "啓動 $appName 服務"
    if [ ! -d "logs" ];then
      mkdir -m 755 logs
    fi
    sh spring-boot.sh start $appName $1
    sh spring-boot.sh status $appName $1
  done
else
  echo "沒有檢測到可執行的jar包,程序停止。。。"
fi
#!/bin/bash

#spring-boot.sh
#jar包啓動腳本2
SpringBoot=$2
current=`date "+%Y-%m-%d %H:%M:%S"`

basepath=/app/tomcat/scms
#本機 IP
IP=$(hostname -I)
#本機 Hostname
service=$2
#Redis集羣節點
nodes="10.11.149.30:6001,10.11.149.30:6002,10.11.149.30:6003,10.11.149.31:6001,10.11.149.31:6002,10.11.149.31:6003,10.11.149.32:6001,10.11.149.32:6002,10.11.149.32:6003,10.11.149.33:6001,10.11.149.33:6002,10.11.149.33:6003,10.11.149.34:6001,10.11.149.34:6002,10.11.149.34:6003"
#數據庫源
DB="jdbc:oracle:thin:@10.12.149.45:1521/loandb"
#數據庫連接池大小
DBmaxActive=300
#註冊中心
defaultZone="http://10.11.149.21:8761/eureka,http://10.11.149.22:8761/eureka"
#日誌路徑
logPath="/app/tomcat/scms/logs"
#日誌級別 默認 ERROR
logLevel="INFO"
#日誌文件大小(需要加size單位:KB,MB...) 默認512000KB
logSize="5GB"
#批量服務中心
job_address="http://10.11.149.191:9090"
#zipkin服務中心
zipkin_address="http://10.11.149.182:9411"

#sessionTime 50小時
sessionTime=360000000

case "$2" in
        "afterloan")
        DBmaxActive=100;;
        "accounting")
        DBmaxActive=100;;
        "archives")
        DBmaxActive=100;;
        "asset")
        DBmaxActive=100;;
        "badassets")
        DBmaxActive=100;;
        "billSystem")
        DBmaxActive=100;;
        "classify")
        DBmaxActive=100;;
        "credit")
        DBmaxActive=100;;
        "customer")
        DBmaxActive=100;;
        "dataApplication")
        DBmaxActive=100;;
        "loan")
        DBmaxActive=100;;
        "rating")
        DBmaxActive=100;;
        "riskwarn")
        DBmaxActive=100;;
        "system")
        DBmaxActive=100;;
        *)
esac

if [ "$1" = "" ];
then
    echo -e "\033[0;31m 未輸入操作名 \033[0m  \033[0;34m {start|stop|restart|status} \033[0m"
    exit 1
fi

if [ "$SpringBoot" = "" ];
then
    echo -e "\033[0;31m 未輸入應用名 \033[0m"
    exit 1
fi

#在 災備環境啓動時 切換環境配置
if [ "$1" == "start" -o "$1" == "restart"  ];then
  if [ "$3" == "dr" ];then
    DB="jdbc:oracle:thin:@10.225.149.45:1521/loandbdr"
    #Redis節點
    nodes="10.224.149.30:6001,10.224.149.30:6002,10.224.149.30:6003,10.224.149.31:6001,10.224.149.31:6002,10.224.149.31:6003,10.224.149.32:6001,10.224.149.32:6002,10.224.149.32:6003,10.224.149.33:6001,10.224.149.33:6002,10.224.149.33:6003,10.224.149.34:6001,10.224.149.34:6002,10.224.149.34:6003"
    #註冊中心
    defaultZone="http://10.224.149.21:8761/eureka,http://10.224.149.22:8761/eureka"
    #批量服務中心
    job_address="http://10.224.149.191:9090"
    #zipkin服務中心
    zipkin_address="http://10.224.149.182:9411"
    echo "........................DB 啓動備庫......................"
  fi
fi

function start()
{        
	count=`ps -ef |grep java|grep $SpringBoot-springboot|grep -v grep|wc -l`
	if [ $count != 0 ];then
	  echo "【$current$SpringBoot is running..."
	else
          if [ ! -d "/app/tomcat/scms/logs" ];then
            mkdir -m 755 /app/tomcat/scms/logs
          fi
	  echo "【$current】Start $SpringBoot success..."
          nohup java  -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=1024m -Xms1024m -Xmx12G -Xmn2G -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC  -jar $basepath/easyloan/$SpringBoot-springboot-1.0.0-SNAPSHOT.jar --spring.profiles.active=pre --edbPath=/app/edb/ --server.tomcat.max-threads=2000 --server.tomcat.connections=2000 --eureka.client.service-url.defaultZone=$defaultZone --spring.redis.lettuce.pool.max-waitMillis=1200 --spring.redis.cluster.nodes=$nodes --spring.redis.cluster.timeout=2500 --spring.redis.cluster.maxAttempts=20 --spring.redis.cluster.max-redirects=3 --server.tomcat.connection-timeout=60000 --server.compression.enabled=true --server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain --server.compression.min-response-size=512 --spring.datasource.druid.master.maxActive=$DBmaxActive --spring.datasource.druid.slave.maxActive=$DBmaxActive --eureka.instance.prefer-ip-address=true --easy.job.admin.addresses=$job_address --easy.job.executor.ip=$IP --feign.httpclient.enabled=true --feign.httpclient.max-connections-per-route=1000 --feign.httpclient.max-connections=3000 --spring.datasource.druid.stat-view-servlet.reset-enable=true --spring.datasource.druid.filter.wall.enabled=true --spring.zipkin.base-url=$zipkin_address --spring.datasource.druid.master.url=$DB  --jwt.expiration=$sessionTime --spring.datasource.druid.slave.url=$DB --application.name=$service --log.path=$logPath --log.level=$logLevel --log.size=$logSize > /dev/null  2>&1 &
	fi
}

function stop()
{
	echo "【$current】Stop $SpringBoot"
	boot_id=`ps -ef |grep java|grep $SpringBoot-springboot|grep -v grep|awk '{print $2}'`
	count=`ps -ef |grep java|grep $SpringBoot-springboot|grep -v grep|wc -l`

	if [ $count != 0 ];then
	    echo $boot_id
	    kill $boot_id
    	count=`ps -ef |grep java|grep $SpringBoot-springboot|grep -v grep|wc -l`

		boot_id=`ps -ef |grep java|grep $SpringBoot-springboot|grep -v grep|awk '{print $2}'`
		echo $boot_id
		kill -9 $boot_id
	fi
}

function restart()
{
	stop
	sleep 2
	start
}

function status()
{
    count=`ps -ef |grep java|grep $SpringBoot-springboot|grep -v grep|wc -l`
    if [ $count != 0 ];then
        echo "【$current$SpringBoot is running..."
    else
        echo "【$current$SpringBoot is not running..."
    fi
}

case $1 in
	start)
	start;;
	stop)
	stop;;
	restart)
	restart;;
	status)
	status;;
	*)

	echo -e "\033[0;31m Usage: \033[0m  \033[0;34m sh  $0  {start|stop|restart|status}  {SpringBootJarName} \033[0m
\033[0;31m Example: \033[0m
	  \033[0;33m sh  $0  start esmart-test.jar \033[0m"
esac
#!/bin/bash
#startall.sh
#停止腳本
# 當 $1 輸入爲 dr 時 啓動備庫

appCount=`(ls *-springboot-1.0.0-SNAPSHOT.jar | wc -l)`
echo "檢測到【${appCount}】個系統服務"
if [ $appCount -gt 0 ];then
  for appTName in $(ls *-springboot-1.0.0-SNAPSHOT.jar)
  do
    #echo "appTName is ${appTName} "
    appName="${appTName%%-*}"
    echo "啓動 $appName 服務"
    if [ ! -d "logs" ];then
      mkdir -m 755 logs
    fi
    sh spring-boot.sh start $appName $1
    sh spring-boot.sh status $appName $1
  done
else
  echo "沒有檢測到可執行的jar包,程序停止。。。"
fi
#startZipkin.sh
#啓動Zipkin
nohup java  -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=1024m -Xms1024m -Xmx12G -Xmn2G -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC  -jar zipkin.jar > zipkin.log  2>&1 &
#stopZipkin.sh
#停止Zipkin
boot_id=`ps -ef |grep java|grep zipkin|grep -v grep|awk '{print $2}'`
count=`ps -ef |grep java|grep zipkin|grep -v grep|wc -l`

if [ $count != 0 ];then
  echo $boot_id
  kill $boot_id
  #count=`ps -ef |grep java|grep zipkin|grep -v grep|wc -l`
  #boot_id=`ps -ef |grep java|grep zipkin|grep -v grep|awk '{print $2}'`
  #echo $boot_id
  #kill -9 $boot_id
  echo "【Stop】 zipkin success!!"
fi
#!/bin/bash
# takeDirForJar.sh
#jar包中提取 文件(夾)
path=BOOT-INF/classes


if [ ! -d "rules" ];then
   mkdir -m 750 rules
fi

for appTName in $(ls *-springboot-1.0.0-SNAPSHOT.jar)
do  
    if [ ! -d "bak" ];then
       mkdir -m 750 bak
    fi

    #echo "appTName is ${appTName} "
    appName="${appTName%%-*}"
    echo "提取 ${appName} 中 rules kettle 文件 "
    if [ ! -d "rules/${appName}" ];then
       mkdir -m 750 rules/${appName}
    fi
    
    cd bak
    rm -rf *
    cp ../${appName}-springboot-1.0.0-SNAPSHOT.jar ./
    for files in $(ls)
    do
      file=${files%\.*}

      echo "創建文件夾:${file}"
      mkdir -m 750 ${file}
      echo "移動文件${files}${file}中"
      mv ${files} $file
      echo "解壓jar包"
      cd $file
        jar xf $files
        echo "刪除原 ${files} 包"
        rm $files
        echo "進入 $path 中"
        cd $path
        echo "複製rules kettle 至 easyloan "
        cp rules/* ../../../../rules/${appName}
        if [ -d "kettle" ];then
          cp -r kettle/ ../../../../
        fi
      cd ../../../../
      echo "此刻路徑: $(pwd)"
      echo "完成${files}中 rules kettle 文件的提取!!!"
      echo ""
      echo ""
   done

done



rm -rf bak
echo "此刻路徑: $(pwd)"
#!/bin/sh
# start.sh
# 啓動(每個)redis

./redis-server ./6001/redis.conf
./redis-server ./6002/redis.conf
./redis-server ./6003/redis.conf
#./redis-server ./6004/redis.conf
#./redis-server ./6005/redis.conf
#./redis-server ./6006/redis.conf

#./redis-cli --cluster create 10.11.149.30:6001 10.11.149.31:6001 10.11.149.32:6001 10.11.149.33:6001 10.11.149.34:6001 10.11.149.35:6001 10.11.149.36:6001 10.11.149.37:6001 10.11.149.38:6001 10.11.149.39:6001 --cluster-replicas 1
  
#!/bin/sh
# 停止redis
/app/redis/redis-5.0.5/src/redis-cli -c -p 6001 shutdown
/app/redis/redis-5.0.5/src/redis-cli -c -p 6002 shutdown
/app/redis/redis-5.0.5/src/redis-cli -c -p 6003 shutdown
/app/redis/redis-5.0.5/src/redis-cli -c -p 6004 shutdown
/app/redis/redis-5.0.5/src/redis-cli -c -p 6005 shutdown
/app/redis/redis-5.0.5/src/redis-cli -c -p 6006 shutdown
#啓動redis集羣 一主兩從
# 創建集羣時 要先啓動每一個 redis
./redis-cli --cluster create 10.224.149.30:6001 10.224.149.30:6002 10.224.149.30:6003 10.224.149.31:6001 10.224.149.31:6002 10.224.149.31:6003 10.224.149.32:6001 10.224.149.32:6002 10.224.149.32:6003 10.224.149.33:6001 10.224.149.33:6002 10.224.149.33:6003 10.224.149.34:6001 10.224.149.34:6002 10.224.149.34:6003 --cluster-replicas 2
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章