shell案例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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案例的主要内容,如果未能解决你的问题,请参考以下文章

Express实战 - 应用案例- realworld-API - 路由设计 - mongoose - 数据验证 - 密码加密 - 登录接口 - 身份认证 - token - 增删改查API(代码片段

用于确保在任何给定时间仅运行一个 shell 脚本的 shell 片段 [重复]

shell 脚本 片段

vue2.0 代码功能片段

在案例演示中嵌入片段

nodejs常用代码片段