Hackosis is an Open Blog. You Can Participate.

  • 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.

Speedometer
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.

  1. #!/bin/sh
  2.  
  3. cd /path/to/choosen/working/dir
  4. filename="/path/to/test.file"
  5. hostname="ftp.server.com"
  6. username="user"
  7. password="password"
  8. echo -e "***FTP SERVER DOWNLOAD SPEED***\n" >> speedtest.log
  9. ftp -inv $hostname >> speedtest.log  <<EOF
  10. quote USER $username
  11. quote PASS $password
  12. binary
  13. put $filename
  14. bye
  15. EOF
  16.  
  17. echo -e "\n"
  18. echo -e "***FTP SERVER UPLOAD SPEED***\n" >> speedtest.log
  19. ftp -inv $hostname >> speedtest.log  <<EOF
  20. quote USER $username
  21. quote PASS $password
  22. binary
  23. get $filename
  24. bye
  25. EOF
  26.  
  27. #REMOVE GARBAGE (REMOVE EVERY LINE EXCEPT FOR ONES CONTAINING ‘*’ AND ‘MB’) FROM LOG FILE AND EMAIL IT
  28. sed -n -e ‘/*/p’ -e ‘/MB/p’ speedtest.log >> email.log
  29. mail -s "Speed Test Results" youremail@whateva.com < /path/to/choosen/working/dir/email.log
  30. rm /path/to/choosen/working/dir/speedtest.log
  31. rm /path/to/choosen/working/dir/email.log

Now we need to add it to cron for execution every hour:

crontab -e

Add the following to your crontab file:

@hourly /path/to/your/speedtest.sh

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.

FTP Speed Test Bash Script

If you have any questions about how this script works, please leave a comment and I will be glad to explain.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Related Posts


Tags: , , , , ,

Like this post? Subscibe to the RSS feed.


One Comment

  1. Linux: Automated FTP Speed Test Bash Script : HowtoMatrix Says:

    [...] Read more at hackosis [...]

Leave a Comment