linux – 如何在scp文件的同时并行化for循环?
发布时间:2020-12-14 02:25:56 所属栏目:Linux 来源:网络整理
导读:我从machineA运行我的下面的 shell脚本,它将文件machineB和machineC复制到machineA.如果文件不在machineB中,那么它应该在machineC中. 下面的shell脚本会将文件复制到machineA中的TEST1和TEST2目录中. #!/bin/bashset -ereadonly TEST1=/data01/test1readonly
我从machineA运行我的下面的
shell脚本,它将文件machineB和machineC复制到machineA.如果文件不在machineB中,那么它应该在machineC中.
下面的shell脚本会将文件复制到machineA中的TEST1和TEST2目录中. #!/bin/bash set -e readonly TEST1=/data01/test1 readonly TEST2=/data02/test2 readonly SERVER_LOCATION=(machineB machineC) readonly FILE_LOCATION=/data/snapshot dir1=$(ssh -o "StrictHostKeyChecking no" david@${SERVER_LOCATION[0]} ls -dt1 "$FILE_LOCATION"/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | head -n1) dir2=$(ssh -o "StrictHostKeyChecking no" david@${SERVER_LOCATION[1]} ls -dt1 "$FILE_LOCATION"/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | head -n1) echo $dir1 echo $dir2 if [ "$dir1" = "$dir2" ] then rm -rf $TEST1/* rm -rf $TEST2/* for el in $test1_partition do scp david@${SERVER_LOCATION[0]}:$dir1/pp_monthly_9800_"$el"_200003_5.data $TEST1/. || scp david@${SERVER_LOCATION[1]}:$dir2/pp_monthly_9800_"$el"_200003_5.data $TEST1/. done for sl in $test2_partition do scp david@${SERVER_LOCATION[0]}:$dir1/pp_monthly_9800_"$sl"_200003_5.data $TEST2/. || scp david@${SERVER_LOCATION[1]}:$dir2/pp_monthly_9800_"$sl"_200003_5.data $TEST2/. done fi https://unix.stackexchange.com/questions/53390/is-there-a-way-to-run-process-parallelly-in-the-loop-of-a-bash-script 目前它首先将文件从machineB和machineC复制到machineA TEST1目录,如果完成,那么只有它会将文件从machineB和machineC复制到machineA TEST2目录..有没有办法我将文件传输到TEST1和TEST2目录同时出现? 我正在运行Ubuntu 12.04 解决方法
更换
done 同 done & 这将在后台启动两个for循环. 并完成脚本: wait 这将等待两个for循环完成. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |