美文网首页
linux下常用的批量处理脚本

linux下常用的批量处理脚本

作者: yinkp001 | 来源:发表于2019-08-16 10:17 被阅读0次

目的:在管理多个linux主机时,为了方便运维和使用,我们一般都会打通主机之间的ssh免密码登陆。在主机之间免密码登陆的前提下,我们就可以批量在这些主机上执行命令和分发文件了,下面就是具体shell脚本。

1.分发文件脚本:deploy.sh

#!/bin/bash

#set -x

if [ $# -lt 2 ]

then

  echo "Usage: ./ deploy.sh Command MachineTag"

  echo "Usage: ./ deploy.sh Command MachineTag confFile"

  exit

fi

file=$1

tag=$2

dir=$3

if [ 'a'$4'a' == 'aa' ]

then

  confFile=~/bin/deploy.conf

else

  confFile=$4

fi

if [ -f $confFile ]

then

    for server in `cat $confFile|grep -v '^#'|grep ','$tag','|awk -F',' '{print $1}'`

    do

      echo "*******************$server***************************"

      #ssh $server "source ~/.bash_profile; $cmd"

        scp -r  $file    $server:$3

    done

else

  echo "Error: Please assign config file or run runRemoteCmd.sh command with deploy.conf in same directory"

fi


2.批量执行命令脚本:runRemoteCmd.sh

#!/bin/bash

#set -x

if [ $# -lt 2 ]

then

  echo "Usage: ./runRemoteCmd.sh Command MachineTag"

  echo "Usage: ./runRemoteCmd.sh Command MachineTag confFile"

  exit

fi

cmd=$1

tag=$2

if [ 'a'$3'a' == 'aa' ]

then

  confFile=~/bin/deploy.conf

else

  confFile=$3

fi

if [ -f $confFile ]

then

    for server in `cat $confFile|grep -v '^#'|grep ','$tag','|awk -F',' '{print $1}'`

    do

      echo "*******************$server***************************"

      ssh $server "source ~/.bash_profile; $cmd"

    done

else

  echo "Error: Please assign config file or run runRemoteCmd.sh command with deploy.conf in same directory"

fi

3.主机列表文件格式:deploy.conf

10.131.127.1,all,

10.131.127.2,all,

10.131.127.9,all,

10.131.127.10,all,

10.131.127.11,all,

10.131.127.12,all,

4.命令格式:

./runRemoteCmd.sh  "ls  /root"  all  deploy.conf

sh deploy.sh  /hdfs/data/yinkp/CDH/test/jdk    all    ~/    deploy.conf

相关文章

  • linux下常用的批量处理脚本

    目的:在管理多个linux主机时,为了方便运维和使用,我们一般都会打通主机之间的ssh免密码登陆。在主机之间免密码...

  • 【编程】kSpider谷歌浏览器爬虫插件

    直接用JavaScript代码批量处理浏览器全部页面,批量向每个页面注入JS脚本甚至JQuery脚本,支持批量保存...

  • 批处理脚本

    shell脚本和批处理,通常就是linux和windows下进行的一些简单脚本执行任务的途径。对于linux来说,...

  • 几个常用的Linux监控脚本

    几个常用的Linux监控脚本 本文介绍了几个常用的Linux监控脚本,可以实现主机网卡流量、系统状况、主机磁盘空间...

  • 整理linux基础命令|2018-10-23

    shell快捷键 | linux 下常用两种脚本 shell - - unix -- Bourne shell b...

  • 大数据学习-Linux Shell脚本快速入门

    批量处理数据,难免会有在集群中使用Shell脚本,自动跑程序,下面快速入门Shell脚本编程,本文解决一下问题: ...

  • 批量处理文件迁移

    批量迁移(使用shell脚本) 新建一个文件用于需要迁移的项目名称及路径 编写脚本用与批量处理git镜像命令

  • oracle数据库,批量插入数据脚本

    批量插入数据脚本1、第一种批量插入数据脚本,可以基本满足要求。理解上较为简单,所以这个最常用。 NEXTVAL和C...

  • Linux Shell 文本处理工具集锦

    Linux Shell 文本处理工具集锦 本文将介绍Linux下使用Shell处理文本时最常用的工具:find、g...

  • Linux I/O复用——epoll()

    编程TWO编程小兔崽今天 epoll是Linux内核为处理大批量文件描述符而作了改进的poll,是Linux下多路...

网友评论

      本文标题:linux下常用的批量处理脚本

      本文链接:https://www.haomeiwen.com/subject/zixfsctx.html