#!/bin/bash # script to test bandwidth to ssh server # it copies a 10MB file to the server and # loads it back down again. # usage: bandwidth user@server # if no server is applied a default server is used # defaults sshserver=birdofprey sshuser=david sshpath="/tmp" localpath="/tmp" file=$RANDOM size=10 #MB # preflight command -v scp &> /dev/null if [[ $? -ne 0 ]]; then echo "scp must be installed first. exiting." exit 1 fi command -v ssh &> /dev/null if [[ $? -ne 0 ]]; then echo "ssh must be installed first. exiting." exit 1 fi command -v python &> /dev/null if [[ $? -ne 0 ]]; then echo "python must be installed first. exiting." exit 1 fi # create file echo "creating $size MB file." dd if=/dev/zero of=$localpath/$file bs=$(($size*1024*1024)) count=1 &> /dev/null if [[ $? -ne 0 ]]; then echo "cannot create file. ($localpath/$file)" exit 1 fi # upload file echo "uploading file to $sshserver" scp -v $localpath/$file $sshuser@$sshserver:$sshpath/$file &> $localpath/bandwidth_scplogup if [ $? -ne 0 ]; then echo "error while uploading file. exiting." echo "there might be information in the scp log. ($localpath/bandwidth_scplogup)" exit 1 fi result=$(cat $localpath/bandwidth_scplogup | grep "Bytes per second" | awk '{print $5}' | sed 's/\,//') result=$(echo $result | sed 's/\..*//') echo "upload (kbit/s): $(($result * 8 / 1024))" rm $localpath/bandwidth_scplogup # download file echo "downloading file from $sshserver." scp -v $sshuser@$sshserver:$sshpath/$file $localpath/$file &> $localpath/bandwidth_scplogdown if [ $? -ne 0 ]; then echo "error while downloading file. exiting." echo "there might be information in the scp log. ($localpath/bandwidth_scplogdown)" exit 1 fi result=$(cat $localpath/bandwidth_scplogdown | grep "Bytes per second" | awk '{print $7}' | sed 's/\,//') result=$(echo $result | sed 's/\..*//') echo "download (kbit/s): $(($result * 8 / 1024))" rm $localpath/bandwidth_scplogdown # remove remote file ssh $sshuser@$sshserver rm $sshpath/$file &> /dev/null if [[ $? -ne 0 ]]; then echo "cannot remove remote file. ($sshpath/$file) - you must fix this!!" sleep 5 else echo "remote file removed." fi # remove local file rm $localpath/$file if [[ $? -ne 0 ]]; then echo "cannot delete local file. exiting. ($localpath/$file) - you must fix this!!" exit 1 else echo "local file has been deleted." exit 0 fi echo "all done. exiting." exit 0