想把hadoop102机器上的环境变量分发给hadoop103和hadoop104,xsync /etc/profile.d/my_env.sh
,
这里的xsync是自己的分发脚本
#!/bin/bash
#1. 判断参数个数
if [ $# -lt 1 ]
then
echo Not Enough Arguement!
exit;
fi
#2. 遍历集群所有机器
for host in hadoop102 hadoop103 hadoop104
do
echo =========== $host =============
#3. 遍历所有目录,挨个发送
for file in $@
do
#4. 判断文件是否存在
if [ -e $file ]
then
#5. 获取父目录
pdir=$(cd -P $(dirname $file); pwd)
#6. 获取当前文件的名称
fname=$(basename $file)
ssh $host "mkdir -p $pdir"
rsync -av $pdir/$fname $host:$pdir
else
echo $file does not exists!
fi
done
done
但是报如下错误:
==================== hadoop102 ====================
sending incremental file list
sent 436 bytes received 17 bytes 906.00 bytes/sec
total size is 16,961 speedup is 37.44
==================== hadoop103 ====================
sending incremental file list
rsync: failed to set times on "/etc/profile.d": Operation not permitted (1)
profile.d/
profile.d/my_env.sh
rsync: mkstemp "/etc/profile.d/.my_env.sh.gwiMC5" failed: Permission denied (13)
sent 970 bytes received 210 bytes 786.67 bytes/sec
total size is 16,961 speedup is 14.37
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1179) [sender=3.1.2]
==================== hadoop104 ====================
sending incremental file list
rsync: failed to set times on "/etc/profile.d": Operation not permitted (1)
profile.d/
profile.d/my_env.sh
rsync: mkstemp "/etc/profile.d/.my_env.sh.ezD90d" failed: Permission denied (13)
sent 970 bytes received 210 bytes 786.67 bytes/sec
total size is 16,961 speedup is 14.37
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1179) [sender=3.1.2]
解决办法
sudo ./bin/xsync /etc/profile.d/my_env.sh
我的xsync脚本放在用户目录下的bin目录下(全局变量环境中),所以 . 这里表示当前在自己的用户目录下