写了2个简单的工具脚本用来分发hdfs集群上的文件到所有节点,和远程执行命令
2015-04-01 15:49
423 查看
#!/bin/bash if [ $# != 2 ]; then echo "useage: $0 <hdfs_file> <dest_dir>" exit 1 fi CURR_PATH="$(cd "`dirname "$0"`"/; pwd)" hosts_file=$CURR_PATH"/hosts" if [ ! -f "$hosts_file" ]; then echo "$hosts_file not exist" exit 1 fi source_file=$1 dest_dir=$2 filename=$(echo $source_file | awk -F '/' '{print $NF}') destfilename=$dest_dir"/"$filename echo $filename echo $destfilename hadoop fs -get $source_file $dest_dir for h in $(cat $hosts_file) do scp $destfilename root@$h:$destfilename done
原理就是在主节点上(能够免秘钥ssh集群其他所有节点)执行该脚本(取名为distribute-file),hdfs_file为hdfs上的一个文件的完整路径,dest_dir为节点本地目录用来存放分发文件的目录。
必须以root用户执行,与该脚本同级目录下面必须放置一个名叫hosts的文件,里面写上你要分发的所有的节点的hostname。
eg.:
./distribute-file /user/hdfs/tmp/fairscheduler.xml /etc/spark
#!/bin/bash if [ $# != 1 ]; then echo "useage: $0 <cmd>" exit 1 fi CURR_PATH="$(cd "`dirname "$0"`"/; pwd)" hosts_file=$CURR_PATH"/hosts" if [ ! -f "$hosts_file" ]; then echo "$hosts_file not exist" exit 1 fi remote_cmd=$1 for h in $(cat $hosts_file) do ssh root@$h "$remote_cmd" done远程分发执行命令脚本(取名叫distribute-exec),通过免秘钥ssh到远程主机上执行命令,用法大体和上面那个脚本相似,也是要当前目录下面放置hosts文件,举例:
./distribute-exec "cd /opt/cloudera/parcels/CDH/lib/spark/lib; rm -f spark-assembly.jar; ln -s spark-assembly-with-hive-cdh5.3.2.jar spark-assembly.jar;"
多个命令之间用分号分隔
相关文章推荐
- 写了2个简单的工具脚本用来分发hdfs集群上的文件到所有节点,和远程执行命令
- 十七周四次课(11月30日) 20.31 expect脚本同步文件 20.32 expect脚本指定host和要同步的文件 20.33 构建文件分发系统 20.34 批量远程执行命令
- linux学习第七十篇:expect脚本同步文件,expect脚本指定host和要同步的文件,构建文件分发系统,批量远程执行命令
- expect脚本同步文件、指定host和要同步的文件、构建文件分发系统、批量远程执行命令
- expect脚本同步文件,expect脚本指定host和要同步的文件,构建文件分发系统,批量远程执行命令
- expect脚本同步文件,构建文件分发系统,批量远程执行命令
- 十七周四次课 2018.03.05 expect脚本同步文件、expect脚本指定host和要同步的文件、构建文件分发系统、批量远程执行命令
- expect脚本同步文件 expect脚本指定host和要同步的文件 构建文件分发系统 批量远程执行命令
- expect脚本同步文件expect脚本指定host和要同步的文件 构建文件分发系统批量远程执行命令
- 远程执行命令和文件分发shell脚本
- 很实用的sh脚本,【批量文件替换】【ssh远程命令执行】【统计某一目录下面所有文档总行数】等
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- 利用python fabric模块写的批量操作远程主机脚本(命令执行,上传、下载文件)
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- 最简单的非交互ssh远程执行命令expect脚本
- 分发系统介绍、expect脚本远程登录、expect脚本远程执行命令、expect脚本传递参数