码迷,mamicode.com
首页 > 系统相关 > 详细

shell案例

时间:2020-04-13 23:14:01      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:int   syn   roo   pre   dir   web   oam   block   root   

这里主要记录一下工作中遇到的一些常用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案例

标签:int   syn   roo   pre   dir   web   oam   block   root   

原文地址:https://blog.51cto.com/13733462/2486929

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!