File tree 3 files changed +66
-0
lines changed
3 files changed +66
-0
lines changed Original file line number Diff line number Diff line change
1
+ FROM alpine:3.14.0
2
+ MAINTAINER LWQ kenan3015@gmail.com
3
+
4
+ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
5
+ && apk add --update --no-cache bash wget \
6
+ && rm -rf /var/cache/apk/*
7
+
8
+ ADD main.sh /tmp/main.sh
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ # #
4
+ # 循环下载文件,目的是增加网络负载
5
+ # 使用 ./main.sh 300k 5 http://localhost:8080/file.txt
6
+ # 其中300k是下载速度上限,作为参数传递给wget --limit-rate
7
+ # 5是sleep时间,单位是秒,如果为0则不sleep,一直循环下载
8
+ # http://localhost:8080/file.txt 是下载文件的url地址
9
+ # #
10
+ set -ex
11
+
12
+ # 默认参数
13
+ limit_rate=500k
14
+ file_url=k8s-master:6000/netload.txt
15
+ interval=1 # 默认秒
16
+ file_name=netload
17
+
18
+ # 使用信息
19
+ usage (){
20
+ cat << -EOF
21
+ Usage: ./main.sh 300k 5 http://localhost:8080/file.txt
22
+ Flags:
23
+ 300k 下载速度上限,作为参数传递给wget --limit-rate
24
+ 5 是sleep时间,单位是秒,如果为0则不sleep,一直循环下载
25
+ http://localhost:8080/file.txt 下载文件的url地址
26
+ Node:
27
+ 必须按顺序指定3个参数,且参数类型要符合规范
28
+ EOF
29
+ }
30
+
31
+ # 主执行逻辑
32
+ main () {
33
+ for (( ; ; ))
34
+ do
35
+ # wget --no-proxy --limit-rate=$limit_rate -O $file_name $file_url
36
+ wget --limit-rate=$limit_rate -O $file_name $file_url
37
+ rm $file_name
38
+ if (( $interval >= 1 )) ; then
39
+ sleep $interval
40
+ fi
41
+ done
42
+ }
43
+
44
+ # 参数
45
+ if test $# -eq 3; then
46
+ limit_rate=$1
47
+ interval=$2
48
+ file_url=$3
49
+ main
50
+ else
51
+ usage
52
+ exit
53
+ fi
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ docker run -d --name netload \
4
+ netload:v1 \
5
+ /tmp/main.sh 300k 1 https://wangdoc.com/bash/condition.html
You can’t perform that action at this time.
0 commit comments