傳輸內(nèi)網(wǎng)寬帶拉滿(mǎn)
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-579545.html
先運(yùn)行接收端 開(kāi)始監(jiān)聽(tīng)
- 接收端腳本 re.sh
#!/bin/bash
#Revision: 1.0
#Author: author
#Email: author@email.com
#Date: 2023/07/16
# 定義接收文件路徑
received_file_path="/root/100.txt"
local_port="6789"
nohup nc -l -p "$local_port" > "$received_file_path" &
使用 ansible 拷貝腳本到其它接收端服務(wù)器
ansible host01 -m copy -a 'src=/root/re.sh dest=/root'
批量運(yùn)行接收端腳本
ansible host01 -m shell -a "bash /root/re.sh"
查看nc是否運(yùn)行
# ps aux | grep nc
nc -l -p 6789
運(yùn)行發(fā)送端
- 發(fā)送端運(yùn)行腳本 se.sh
#!/bin/bash
# 定義待傳輸文件路徑
file_path="/root/100.txt"
remote_port="6789"
remote_hosts_file="/root/hostlist.txt"
# 讀取遠(yuǎn)程主機(jī)列表文件,保存到數(shù)組中
readarray -t remote_hosts < "$remote_hosts_file"
for host in "${remote_hosts[@]}"; do
# 去除每行首尾的空格和換行符
host="$(echo -e "${host}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
echo "host = $host , port = $remote_port"
# 向目標(biāo)主機(jī)發(fā)送文件
cat "$file_path" | nc -w 10 "$host" "$remote_port" &
echo "host = $host 開(kāi)始傳輸"
done
wait
echo "文件傳輸完成"
-
hostlist.txt
為接收端IP
# cat hostlist.txt
192.168.20
192.168.21
192.168.22
運(yùn)行發(fā)送端腳本開(kāi)始傳輸文件
bash se.sh
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-579545.html
到了這里,關(guān)于linux 內(nèi)網(wǎng)批量快速傳輸大文件 nc的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!