【甘道夫】拷贝文件到多台服务器的Shell脚本
2014-04-10 17:24
253 查看
在多机集群环境中,经常面临修改配置文件后拷贝到多台服务器的情况,传统的执行scp比较麻烦,所以写了以下shell脚本,可以将指定文件拷贝到多台机器。
使用方法请参见HELP部分代码。
#!/bin/bash
help()
{
cat << HELP
--------------HELP------------------------
This shell script can copy file to many computers.
Useage:
copytoall filename(full path form /home) targetpathfrom/ username ip1 ip2 ip3....
Example:
copytoall /home/casliyang/hadoop-2.2.0/etc/hadoop/core-site.xml /home/casliyang/hadoop-2.2.0/etc/hadoop/ casliyang 192.168.0.5 192.168.0.6 192.168.0.7 192.168.0.8
------------------------------------------
HELP
exit 0
}
currentdate=$(date +%Y-%m)
echo $currentdate " execute copytoall"
if [ $1 = "-h" ] ; then
help
exit 0
fi
file=$1
shift
targetpath=$1
shift
user=$1
shift
tempip=0
if [ -f $file ] ; then
while [ $# -gt 0 ] ; do
tempip=$1
shift
scp $file ${user}@${tempip}:${targetpath}
done
else
echo "wrong file!"
exit 0
fi
使用方法请参见HELP部分代码。
#!/bin/bash
help()
{
cat << HELP
--------------HELP------------------------
This shell script can copy file to many computers.
Useage:
copytoall filename(full path form /home) targetpathfrom/ username ip1 ip2 ip3....
Example:
copytoall /home/casliyang/hadoop-2.2.0/etc/hadoop/core-site.xml /home/casliyang/hadoop-2.2.0/etc/hadoop/ casliyang 192.168.0.5 192.168.0.6 192.168.0.7 192.168.0.8
------------------------------------------
HELP
exit 0
}
currentdate=$(date +%Y-%m)
echo $currentdate " execute copytoall"
if [ $1 = "-h" ] ; then
help
exit 0
fi
file=$1
shift
targetpath=$1
shift
user=$1
shift
tempip=0
if [ -f $file ] ; then
while [ $# -gt 0 ] ; do
tempip=$1
shift
scp $file ${user}@${tempip}:${targetpath}
done
else
echo "wrong file!"
exit 0
fi
相关文章推荐
- 【甘道夫】拷贝文件到多台服务器的Shell脚本
- [小记]将windows下的文件拷贝到多台linux服务器下
- 从一台服务器向另一台服务器拷贝文件
- 通过python模块实现服务器和本地机器之间快速拷贝文件
- linux下使用scp在服务器之间拷贝文件
- 服务器文件拷贝,移动
- 利用scp把一个服务器上面的文件拷贝到另一服务器上面1,
- linux两台服务器之间文件/文件夹拷贝
- SCP--服务器之间拷贝文件
- CentOS两台服务器利用scp拷贝文件
- php中本地文件拷贝至远程服务器的实现方式
- WindowsServices_无法拷贝文件到服务器
- ssh链接服务器并且拷贝文件
- 2台服务器之间拷贝文件
- bash deploy.sh 通过bash命令 执行scp -r 命令将本地文件拷贝到服务器
- linux 两台服务器文件拷贝
- 【system】 linux 服务器之间拷贝文件
- 【Linux笔记】在后台执行scp,实现服务器间无密码文件拷贝。
- Linux下SCP命令在服务器之间拷贝文件的命令用法
- SSH连接服务器并且拷贝文件