Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write a shell script to test the download speed

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to write a shell script to test the download speed". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to write a shell script to test the download speed.

Test the download degree with Shell under Linux. The code is as follows:

The code is as follows:

#! / bin/bash

# date:20140210

# used for test server download speed

Ritual host = "188.18.28.19"

Ringing dirt = "/ home/test0208/tmp"

Ringing file = "$r_dir/ddfile2m"

Lumped dirt = "/ home/yangjuying/tmp"

Lumped file = "$l_dir/ddfile2m"

Lumped log = "$l_dir/182.18.28.19-download.log"

Echo "- $(date +% Y%m%d-%H%M%S) -" > > $l_log

Start_t= "$(date + s)"

Scp-P22-o connecttimeout=10-o GSSAPIAuthentication=no test0208@$r_host:$r_file $l_file > > $l_log 2 > & 1

Rc= "$?"

If ["$rc"-eq 0]; then

Stop_t= "$(date + s)"

File_stat= "$(stat $l_file)"

File_ctime= "$(echo" $file_stat "| awk-F" [.] "'FNR==5 {print $2 camera 3}' | sed's / [-:] / / g')"

File_ct= "$(awk-v t =" $file_ctime "'BEGIN {print mktime (t)}')"

File_size= "$(du-sm $l_file | cut-F1)"

Rm "$l_file"

Else

Stop_t= ""

Fi

If [- n "$stop_t"]; then

Connect_t=$ (($file_ct-$start_t))

Transfer_t=$ (($stop_t-$file_ct))

All_t=$ (($stop_t-$start_t))

Speed= "$(echo" scale=3;$file_size/$transfer_t "| bc)"

Echo "size:$ {file_size} MB, all_time:$all_t, connect_time:$connect_t, transfer_time:$transfer_t, speed:$ {speed} MB/s" > $l_log

Else

Echo "scp error!" > > $l_log

Fi

At this point, I believe you have a deeper understanding of "how to write a shell script to test the download speed". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report