It copys one specified file to multiple "unique"(filter those different pathnames which in fact point to the same physical path) paths with parallelism in bash. In contrast to sequential copy processes, it performs well under multiprocessor systems.
The efficiency of Co-process is normally determined by three factors:
1.Whether CPU bound or not
2.Whether scientific data processing or not
3.Whether I/O or not
#!/bin/sh
#
# Written by home_king <home_king@163.com>
# mcp---Multiple copy with Co-Process
# command format:
# mcp filename pathname1 pathname2 ... pathnameN
#
checkargs(){
if [ $# -eq 0 ];then
echo 'No arguments supplied!'
return 1
fi
cpfile=$1
if [ ! -f $cpfile ]; then
echo 'Invaild file to copy!'
return 1
fi
shift
for tmparg in "$@"; do
if [ ! -d $tmparg ];then
echo "There's at least one invalid directory"
return 1
fi
done
argnums=($(echo $(stat -Lc %i $@) | awk -v inum=$(stat -c %i $PWD) '{for(i=1;i<=NF;i++){if($i == inum)continue;ldirs[$i]=i}} END{for(item in ldirs){print ldirs[item]}}'))
}
checkargs $@
[ $? -eq 0 ] || exit 1
shift
echo "Destination:"
for arg in "${argnums[@]}"; do
eval echo '$'$arg
eval cp -f $cpfile '$'$arg &
done
wait
echo ""
echo 'All done!'
Welcome to www.linuxsir.org/bbs : )