1
1
Fork 0

added bandwidth.sh

This commit is contained in:
david 2015-10-12 21:31:44 +02:00
parent 1be2bd80b7
commit f79c4fdf0e
1 changed files with 84 additions and 0 deletions

84
bandwidth.sh Executable file
View File

@ -0,0 +1,84 @@
#!/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 [ $? -eq 0 ]; then
echo upload was successful
fi
result=$(cat $localpath/bandwidth_scplogup | grep "Bytes per second" | awk '{print $5}' | sed 's/\,//')
echo "upload (bytes/s): $result"
rm $localpath/bandwidth_scplogup
# download file
echo "downloading file from $sshserver."
scp -v $sshuser@$sshserver:$sshpath/$file $localpath/$file &> $localpath/bandwidth_scplogdown
result=$(cat $localpath/bandwidth_scplogdown | grep "Bytes per second" | awk '{print $7}' | sed 's/\,//')
echo "download (bytes/s): $result"
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