- 05
- Jun
If you haven’t noticed, my posting has slowed to a crawl lately. I have been very busy at working on maintaining hundreds of systems and that leaves little time for much else. Enough with excuses and on to a bash script that you might be interested in.

image by Kirill
Ever have bandwidth issues and wish you could automated the testing process instead of manually testing every other hour of the day? I have.
By using the bash script below we are able to automate an upload and download of a file and email the speed results.
-
#!/bin/sh
-
-
cd /path/to/choosen/working/dir
-
filename="/path/to/test.file"
-
hostname="ftp.server.com"
-
username="user"
-
password="password"
-
echo -e "***FTP SERVER DOWNLOAD SPEED***\n" >> speedtest.log
-
ftp -inv $hostname >> speedtest.log <<EOF
-
quote USER $username
-
quote PASS $password
-
binary
-
put $filename
-
bye
-
EOF
-
-
echo -e "\n"
-
echo -e "***FTP SERVER UPLOAD SPEED***\n" >> speedtest.log
-
ftp -inv $hostname >> speedtest.log <<EOF
-
quote USER $username
-
quote PASS $password
-
binary
-
get $filename
-
bye
-
EOF
-
-
#REMOVE GARBAGE (REMOVE EVERY LINE EXCEPT FOR ONES CONTAINING ‘*’ AND ‘MB’) FROM LOG FILE AND EMAIL IT
-
sed -n -e ‘/*/p’ -e ‘/MB/p’ speedtest.log >> email.log
-
mail -s "Speed Test Results" youremail@whateva.com < /path/to/choosen/working/dir/email.log
-
rm /path/to/choosen/working/dir/speedtest.log
-
rm /path/to/choosen/working/dir/email.log
Now we need to add it to cron for execution every hour:
Add the following to your crontab file:
Don’t forget to chmod 755 the script to make it executable. I have also attached the script in case of any formatting issues on this web page.
If you have any questions about how this script works, please leave a comment and I will be glad to explain.
Related Posts
Tags: Bandwidth, Bash, Cron, FTP, Linux, Speedtest



June 12th, 2008 at 11:52 am
[...] Read more at hackosis [...]