shell分发文件脚本
配置文件scp.conf
ssh_hosts=("IP") #需要分发机器的所有IP
ssh_ports=("22")
ssh_users=("root")
ssh_passwords=("密码")
except免秘钥脚本
#!/usr/bin/expect
#host
set scphost "[lindex $argv 0]"
#ssh端口
set port "[lindex $argv 1]"
#ssh用户名
set scpuser "[lindex $argv 2]"
#ssh密码
set scppw "[lindex $argv 3]"
#要上传的文件名或者目录
set file "[lindex $argv 4]"
#要上传到远程机器的文件名或者目录
set target "[lindex $argv 5]"
`scp -r -P $port $file $scpuser@$scphost:$target`
scp分发脚本
#用来通过scp批量上传文件或者目录到目标机器的指定目录
#配置文件格式:
#ssh_hosts=("1.1.1.1" "2.2.2.2")
#ssh_ports=("22" "22")
#ssh_users=("root" "root")
#ssh_passwords=("12" "23")
#执行:sh multi_scp.sh conf_file_path file target #upload shell script file path
scp_upload=scp_upload.sh
#then upload file path
scp_file=$1
#remote host'target file or dir path
scp_target=$2 conf_file=scp.conf
if [ $# == 3 ]
then
conf_file=$3
fi #判断conf_file配置文件是存在
if [ ! -e "$conf_file" ]
then
echo "$conf_file is not exists";
exit;
fi
#判断scp_file是文件或者目录
if [ ! -e "$scp_file" ] && [ ! -d "$scp_file" ]
then
echo ""
#echo "$scp_file is not exists";
#exit;
fi
#read configure file
source $conf_file
for((i=0;i<${#ssh_hosts[@]};i++))
do
#remote ssh host
ssh_host=${ssh_hosts[$i]}; #remote ssh port
ssh_port=${ssh_ports[0]}; #remote ssh user
ssh_user=${ssh_users[0]}; #remote ssh password
ssh_password=${ssh_passwords[0]}; while read line
do
target_path=`echo $line | awk '{print $1}'` #echo "["`date +"%F %T"`"] (scp -r $scp_file $ssh_user@$ssh_host:$ssh_port:$target_path) start"
#`scp -r -P $port $file $scpuser@$scphost:$target`
#scp file or dir
echo "to "$ssh_host":"$target_path
scp -r -P $ssh_port $scp_file $ssh_use@$ssh_host:$target_path #echo "["`date +"%F %T"`"] (scp -r $scp_file $ssh_user@$ssh_host:$ssh_port:$target_path) end"
#echo ""
done < $scp_target
done
记录下,怕以后找不到了
shell分发文件脚本的更多相关文章
- shell 处理文件脚本
[root@centos-6 ~]# cat info_file.txt lys:28:shanxi zhy:28:shanxi [root@centos-6 ~]# cat info_file2.t ...
- hadoop_批量命令脚本&同步文件脚本
1.xcall.sh 批量命令脚本,例:xcall.sh jps ,查看hadoop101~ hadoop104的jps进程 注意:在执行命令的时候,若是提示没有这个命令,但是在本机又可以执行,记得在 ...
- Shell 分发脚本
目录 Shell分发脚本 原理 rsync命令分析 特点 基本语法 实现 需求 环境变量 脚本实现 知识点 获得当前路径的目录dirname 获得当前路径的文件名basename shell远程执行命 ...
- Shell执行将脚本里的变量打印到指定日志文件
首先需要定位获取任务的运行日志或者报错信息,才能定位问题. 通过shell调用有些脚本的话,日志信息会打印在shell里.不过也有用户在shell里调用正常,但是到crontab调用的时候就出错并且没 ...
- Hadoop概念学习系列之Java调用Shell命令和脚本,致力于hadoop/spark集群(三十六)
前言 说明的是,本博文,是在以下的博文基础上,立足于它们,致力于我的大数据领域! http://kongcodecenter.iteye.com/blog/1231177 http://blog.cs ...
- Bash Shell启动配置脚本的顺序
1.Bash检查环境变量文件的方式,取决于系统运行Shell的方式,通常系统运行Shell有3种方式: )通过系统用户登陆后默认运行的Shell )非登陆交互式运行Shell )执行脚本运行非交互式S ...
- Shell编程-01-Shell脚本初步入门
目录 什么是Shell 什么是Shell脚本 Shell脚本语言的种类 常用操作系统默认Shell Shell 脚本的建立和执行 脚本规范 什么是Shell 简单来说Shell其实就是一个命令 ...
- Shell编程(脚本)的经常使用命令和语句
一些经常使用的Shell编程(脚本)命令和语句,能够满足一般需求. 接收到的命令參数: 參数个数: $# 參数值: 命令本身:$0 第一个參数:$1 第二个參数:$2 -- 退出命令: exit ec ...
- Shell,Bash,等脚本学习(有区别)
二元比较操作符,比较变量或者比较数字.注意数字与字符串的区别. 整数比较 -eq 等于,如:if [ "$a" -eq "$b" ] -n ...
随机推荐
- LeetCode:22. Generate Parentheses(Medium)
1. 原题链接 https://leetcode.com/problems/generate-parentheses/description/ 2. 题目要求 给出一个正整数n,请求出由n对合法的圆括 ...
- 类的__new__方法使用
class Person(object): def __init__(self): self.name ="aaa" def defineName(self): self.name ...
- nginx proxy_cache缓存详解
目录 1. 关于缓冲区指令 1.1 proxy_buffer_size 1.2 proxy_buffering 1.3 proxy_buffers 1.4 proxy_busy_buffers_siz ...
- Go中的系统Signal处理
package main import "fmt" import "os" import "os/signal" import " ...
- 【HNOI2008】玩具装箱TOY & 斜率优化学习笔记
题目 P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为 \(1\cdots N\ ...
- django中判断当前user具有是否有对模块的增删改查权限
首先简单了解一下user的一些属性 User对象 User对象是认证系统的核心.用户对象通常用来代表网站的用户,并支持例如访问控制.注册用户.关联创建者和内容等.在Django认证框架中只有一个用户类 ...
- 切换pip源的简便方法
网上大部分帖子讲的都是打开配置文件修改,那样太麻烦了,其实只要一行命令搞定: pip config set global.index-url https://pypi.tuna.tsinghua.ed ...
- python基础训练营03——字典、集合、判断、循环
一.字典dict: 相比列表list而言,列表list像一本书,如果要查书中的某一个内容,需要把书从前往后翻一遍,直到找到想要获取的东西:而字典dict,就像现实中的字典一样,通过查找特定的字或者词( ...
- 核方法(Kernel Methods)
核方法(Kernel Methods) 支持向量机(SVM)是机器学习中一个常见的算法,通过最大间隔的思想去求解一个优化问题,得到一个分类超平面.对于非线性问题,则是通过引入核函数,对特征进行映射(通 ...
- tensorflow学习笔记(2)-反向传播
tensorflow学习笔记(2)-反向传播 反向传播是为了训练模型参数,在所有参数上使用梯度下降,让NN模型在的损失函数最小 损失函数:学过机器学习logistic回归都知道损失函数-就是预测值和真 ...