export命令用于将shell变量输出为环境变量,或者将shell函数输出为环境变量。
cat /data/scripts/hosts
10.19.27.154
10.19.49.44
10.19.1.99
10.19.8.231
10.19.18.137
10.19.147.145
把/data/scripts/hosts文件里多个远程主机上/data/replay/下的数据同步到本地/data/replay/的实现:
#!/bin/bash
source /etc/profile
hostfile="/data/scripts/hosts"
function datasync
{
/usr/bin/rsync -qart $1:/data/replay/ /data/replay/
}
export -f datasync
export hostfile
xargs --arg-file=${hostfile} --max-procs=12 -n 1 -I {} sh -c " datasync {} "