changed bandwitdh.sh
This commit is contained in:
parent
d3aeed67b6
commit
24f87bea7e
35
bandwidth.sh
35
bandwidth.sh
|
@ -5,7 +5,6 @@
|
|||
# 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
|
||||
|
||||
|
@ -17,6 +16,19 @@ localpath="/tmp"
|
|||
file=$RANDOM
|
||||
size=10 #MB
|
||||
|
||||
# config
|
||||
if [ $# -ne 0 ]; then
|
||||
sshuser=$(echo $1 | sed 's/@.*//')
|
||||
sshserver=$(echo $1 | sed 's/.*@//')
|
||||
if [ $# -gt 1 ]; then
|
||||
echo "too much arguments. exiting."
|
||||
exit 1
|
||||
fi
|
||||
echo "using custom server. ($sshuser@$sshserver)"
|
||||
else
|
||||
echo "using default server. ($sshuser@$sshserver)"
|
||||
fi
|
||||
|
||||
# preflight
|
||||
command -v scp &> /dev/null
|
||||
if [[ $? -ne 0 ]]; then
|
||||
|
@ -49,7 +61,18 @@ scp -v $localpath/$file $sshuser@$sshserver:$sshpath/$file &> $localpath/bandwid
|
|||
if [ $? -ne 0 ]; then
|
||||
echo "error while uploading file. exiting."
|
||||
echo "there might be information in the scp log. ($localpath/bandwidth_scplogup)"
|
||||
|
||||
# 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
|
||||
exit 1
|
||||
|
||||
fi
|
||||
result=$(cat $localpath/bandwidth_scplogup | grep "Bytes per second" | awk '{print $5}' | sed 's/\,//')
|
||||
result=$(echo $result | sed 's/\..*//')
|
||||
|
@ -62,7 +85,17 @@ scp -v $sshuser@$sshserver:$sshpath/$file $localpath/$file &> $localpath/bandwid
|
|||
if [ $? -ne 0 ]; then
|
||||
echo "error while downloading file. exiting."
|
||||
echo "there might be information in the scp log. ($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
|
||||
exit 1
|
||||
|
||||
fi
|
||||
result=$(cat $localpath/bandwidth_scplogdown | grep "Bytes per second" | awk '{print $7}' | sed 's/\,//')
|
||||
result=$(echo $result | sed 's/\..*//')
|
||||
|
|
Loading…
Reference in New Issue