-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftpclient
executable file
·71 lines (58 loc) · 1.82 KB
/
ftpclient
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Check if at least one argument is passed
if [ $# -eq 1 ]; then
hostname=$1
iterations=-1
else
if [ $# -eq 2 ]; then
hostname=$1
iterations=$2
else
echo "Syntax: ftpclient hostname or ftpclient hostname iterations"
exit 1
fi
fi
#filename="1gb-file"
#filename="512mb-file"
filename="256mb-file"
# Set the LC_NUMERIC environment variable to use a comma as the decimal separator
LC_NUMERIC="en_US.UTF-8" # Adjust the locale as needed
mkdir ~/tmp 2> /dev/null
cd ~/tmp
rm $filename 2> /dev/null
# Initialize variables for statistics
total_requests=0
total_time=0
# Function to calculate and display statistics
display_statistics() {
if [ $total_requests -gt 0 ]; then
average_time=$(bc -l <<< "scale=4; $total_time / $total_requests")
printf "statistics after %d requests:\n" $total_requests
printf "total time: %.4f seconds\n" $total_time
printf "average time per request: %.4f seconds\n" $average_time
fi
exit 0
}
# Set up a trap for Ctrl+C to call the statistics function
trap 'display_statistics' SIGINT
while [[ $iterations -ne 0 ]]; do
start_time=$(date +%s.%N)
lftp -e "get $filename;exit" $hostname:2121 -u mn-wifi,mn-wifi > /dev/null
end_time=$(date +%s.%N)
response_time=$(echo "$end_time - $start_time" | bc)
printf "download time: %.4f seconds\n" $response_time
#lftp -u mn-wifi,mn-wifi -e "get $filename;exit" localhost:2121 | awk -F '[()]' '{print $(NF-1)}'
# Check the exit code of the command
if [ $? -ne 0 ]; then
echo "lftp execution failed"
exit 1
fi
rm $filename
# Update statistics
total_requests=$((total_requests + 1))
total_time=$(bc -l <<< "scale=2; $total_time + $response_time")
# decrease iterations number
iterations=$((iterations - 1))
sleep 1
done
display_statistics