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

记录下,怕以后找不到了

posted @ 2017-01-13 18:42  梦轻尘  阅读(1775)  评论(1编辑  收藏  举报