shell案例

这里主要记录一下工作中遇到的一些常用shell

1.jenkins部署远程tomcat

#/bin/bash
export TOMCAT_HOME_PATH=/usr/local/soft/tomcat-8.5.53
cd $TOMCAT_HOME_PATH
#停服;
pid=`ps -ef | grep tomcat | grep -v grep | awk ‘{print $2}‘`
`kill -9 $pid`
#备份war包
date_now=`date ‘+%Y%m%d%H%M%S‘`
`cp ./webapps/demo-0.0.1-SNAPSHOT.jar ./webapps_back/demo-0.0.1-SNAPSHOT.jar_$date_now`
`cp /usr/local/package/demo-0.0.1-SNAPSHOT.jar ./webapps/`
./bin/startup.sh
echo "tomcat start success"

2.向集群节点发送文件

#!/bin/bash
#this is shell local system hadoop send it hadoop system
#if input arguments is not empty
if [ $# -le 0 ]
then
        echo "you input arguments is empty"
        exit 1;
fi
#get filename and dirname
filename=`basename $1`
dirname=`cd -P $(dirname $1);pwd`
user=`whoami`

for(( host=1;host<=5;host++ ))
do
        echo "---------------- hadoop$host begin  ----------------"
        sync -lrv  "${dirname}/${filename} ${user}@hadoop${host}:${dirname}"
        #sync -lrv /tmp/a.txt root@hadoop2:/tmp
        echo "---------------- hadoop$host end -------------------"     
done

3.批量执行命令

#!/bin/bash
if [ $# -le 0 ]
then
    echo "you input arguments is empty"
    exit 1;
fi  
for(( host=1;host<=5;host++ ))
do
    echo "---------------- hadoop$host begin  ----------------"
    ssh "hadoop${host} $@"
    echo "---------------- hadoop$host end -------------------" 
done

shell案例

上一篇:Linux解压、压缩文件到指定目录


下一篇:ios网络学习------11 原生API文件上传之断点续传思路