linux – 如何在scp文件的同时并行化for循环?

linux – 如何在scp文件的同时并行化for循环?,第1张

概述我从machineA运行我的下面的 shell脚本,它将文件machineB和machineC复制到machineA.如果文件不在machineB中,那么它应该在machineC中. 下面的shell脚本会将文件复制到machineA中的TEST1和TEST2目录中. #!/bin/bashset -ereadonly TEST1=/data01/test1readonly TEST2=/ 我从machineA运行我的下面的 shell脚本,它将文件machineB和machineC复制到machineA.如果文件不在machineB中,那么它应该在machineC中.

下面的shell脚本会将文件复制到machineA中的TEST1和TEST2目录中.

#!/bin/bashset -eReadonly TEST1=/data01/test1Readonly TEST2=/data02/test2Readonly SERVER_LOCATION=(machineB machineC)Readonly file_LOCATION=/data/snapshotdir1=$(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 $dir1echo $dir2if [ "$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/.    donefi

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循环完成.

总结

以上是内存溢出为你收集整理的linux – 如何在scp文件的同时并行化for循环?全部内容,希望文章能够帮你解决linux – 如何在scp文件的同时并行化for循环?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/yw/1033647.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存