首先你所操作的各台linux机器间必须设置了ssh免密码登录,具体方法可上网查看。将文件从一台linux机器拷贝到多台分为以下几个步骤:

第一步:创建脚本文件remotecopy.sh

#!/bin/bash
while getopts f: OPT;
do
	case $OPT in
		f|+f)
			files="$OPTARG $files"
			;;
		*)
			echo "usage: `basename $0` [-f hostfile] <from> <to>"
			exit 2
	esac
done
shift `expr $OPTIND - 1`

if [ "" = "$files" ];
then
	echo "usage: `basename $0` [-f hostfile] <from> <to>"
	exit
fi

for file in $files
do
	if [ ! -f "$file" ];
	then
		echo "no hostlist file:$file"
		exit
fi
hosts="$hosts `cat $file`"
done

for host in $hosts;
do
	echo "do $host"
	scp $1 root@$host:$2
done

  

第二步:创建主机列表文件hosts

vim hosts

192.16.8.103
192.16.8.101  


第三步:在传输文件所在节点上运行脚本命令

./remotecopy.sh -f /usr/local/host /usr/local/test /usr/local/

就可以将文件/usr/local/test拷贝到其他主机的/usr/local/目录下了

 

相关文章:

  • 2021-04-12
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2021-08-01
  • 2021-12-31
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2021-06-28
相关资源
相似解决方案