Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write a shell script to test the download speed

Shulou Source: shulou.com Published: 2022-06-03 07:48:55 10月04日 Update

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!

Tags: Tests scripts speed code content learning practicality deeper interest practicality practicality simplicity of operation methods more friends websites channels queries Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi vpn MariaDB Microsoft