配置文件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分发文件脚本的更多相关文章

  1. shell 处理文件脚本

    [root@centos-6 ~]# cat info_file.txt lys:28:shanxi zhy:28:shanxi [root@centos-6 ~]# cat info_file2.t ...

  2. hadoop_批量命令脚本&同步文件脚本

    1.xcall.sh 批量命令脚本,例:xcall.sh jps ,查看hadoop101~ hadoop104的jps进程 注意:在执行命令的时候,若是提示没有这个命令,但是在本机又可以执行,记得在 ...

  3. Shell 分发脚本

    目录 Shell分发脚本 原理 rsync命令分析 特点 基本语法 实现 需求 环境变量 脚本实现 知识点 获得当前路径的目录dirname 获得当前路径的文件名basename shell远程执行命 ...

  4. Shell执行将脚本里的变量打印到指定日志文件

    首先需要定位获取任务的运行日志或者报错信息,才能定位问题. 通过shell调用有些脚本的话,日志信息会打印在shell里.不过也有用户在shell里调用正常,但是到crontab调用的时候就出错并且没 ...

  5. Hadoop概念学习系列之Java调用Shell命令和脚本,致力于hadoop/spark集群(三十六)

    前言 说明的是,本博文,是在以下的博文基础上,立足于它们,致力于我的大数据领域! http://kongcodecenter.iteye.com/blog/1231177 http://blog.cs ...

  6. Bash Shell启动配置脚本的顺序

    1.Bash检查环境变量文件的方式,取决于系统运行Shell的方式,通常系统运行Shell有3种方式: )通过系统用户登陆后默认运行的Shell )非登陆交互式运行Shell )执行脚本运行非交互式S ...

  7. Shell编程-01-Shell脚本初步入门

    目录 什么是Shell 什么是Shell脚本 Shell脚本语言的种类 常用操作系统默认Shell Shell 脚本的建立和执行 脚本规范 什么是Shell     简单来说Shell其实就是一个命令 ...

  8. Shell编程(脚本)的经常使用命令和语句

    一些经常使用的Shell编程(脚本)命令和语句,能够满足一般需求. 接收到的命令參数: 參数个数: $# 參数值: 命令本身:$0 第一个參数:$1 第二个參数:$2 -- 退出命令: exit ec ...

  9. Shell,Bash,等脚本学习(有区别)

    二元比较操作符,比较变量或者比较数字.注意数字与字符串的区别.   整数比较   -eq        等于,如:if [ "$a" -eq "$b" ] -n ...

随机推荐

  1. shell eval命令使用

    eval命令将会首先扫描命令行进行所有的置换,然后再执行该命令. 该命令适用于那些一次扫描无法实现其功能的变量.该命令对变量进行两次扫描. 这些需要进行两次扫描的变量有时被称为复杂变量.不过这些变量本 ...

  2. JAXB轻松转换xml对象和java对象

    实体类如下: package com.cn.entity; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; ...

  3. Virtual Host on Apache(Apache上建立虚拟主机)

    0. Introduction Usually, we want to build two or more websites on a web server, but we have only one ...

  4. SGU刷题之路,开始了

    0. 关于SGU的简介 SGU的网址是:acm.sgu.ru 向不了解的同学介绍一下SGU这个题库: 1. 题目难度很高,题目大多很经典. 2. 其数据范围很小,时间和空间要求也都很小,同时很精确.甚 ...

  5. ionic 入口禁止加载其他页面

    .state('memberOrders', { prefetchTemplate: false, url: '/memberOrders', templateUrl: '/MemberOrders' ...

  6. 如何修改Github上提交的错误用户地址和姓名

    Changing author info  https://help.github.com/articles/changing-author-info/   To change the name an ...

  7. Linux-Shell脚本编程-学习-7-总结前面开启后面的学习

    国庆前期后国庆回来也都比较忙,把书一放下,在那起来,就难了,发现好多都开始忘记了,今天好不容易硬着头片看来两章,算是马马虎虎的把前面的基础性质的只是看完了吧. 后面讲开始学习Shell编程的高级阶段, ...

  8. c# 3D图形处理库

    C#的OpenGL类库SharpGL SharpGL 可以让你在 Windows Forms 或者 WPF 应用中轻松的使用 OpenGL 开发图形应用.更多SharpGL信息 Axiom 3D En ...

  9. spring boot 过滤器实现接收 压缩数据 并解压

    1.新加类GzipRequestWrapper 继承HttpServletRequestWrapper类 public class GzipRequestWrapper extends HttpSer ...

  10. Dijkstra模板 dj斯特拉

    图论里非常常用的dijkstra,自己加了个路径查找,做个模板吧: ; struct Edge { int from,to,dist; Edge(int u, int v, int d):from(u ...