1
1
Fork 0

changed bandwidth.sh

This commit is contained in:
david 2015-10-12 22:46:45 +02:00
parent c81feb28c6
commit 4a98685c75
1 changed files with 31 additions and 13 deletions

View File

@ -15,6 +15,7 @@ sshpath="/tmp"
localpath="/tmp"
file=$RANDOM
size=10 #MB
silent=1
# config
if [ $# -ne 0 ]; then
@ -24,9 +25,13 @@ if [ $# -ne 0 ]; then
echo "too much arguments. exiting."
exit 1
fi
echo "using custom server. ($sshuser@$sshserver)"
if [ $silent -ne 1 ]; then
echo "using custom server. ($sshuser@$sshserver)"
fi
else
echo "using default server. ($sshuser@$sshserver)"
if [ $silent -ne 1 ]; then
echo "using default server. ($sshuser@$sshserver)"
fi
fi
# preflight
@ -47,7 +52,9 @@ if [[ $? -ne 0 ]]; then
fi
# create file
echo "creating $size MB file."
if [ $silent -ne 1 ]; then
echo "creating $size MB file."
fi
dd if=/dev/zero of=$localpath/$file bs=$(($size*1024*1024)) count=1 &> /dev/null
if [[ $? -ne 0 ]]; then
@ -56,7 +63,9 @@ if [[ $? -ne 0 ]]; then
fi
# upload file
echo "uploading file to $sshserver"
if [ $silent -ne 1 ]; then
echo "uploading file to $sshserver"
fi
scp -v $localpath/$file $sshuser@$sshserver:$sshpath/$file &> $localpath/bandwidth_scplogup
if [ $? -ne 0 ]; then
echo "error while uploading file. exiting."
@ -66,10 +75,10 @@ if [ $? -ne 0 ]; then
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
if [ $silent -ne 1 ]; then
echo "local file has been deleted."
fi
fi
exit 1
@ -80,7 +89,9 @@ echo "UPLOAD: $(($result * 8 / 1024)) kbit/s"
rm $localpath/bandwidth_scplogup
# download file
echo "downloading file from $sshserver."
if [ $silent -ne 1 ]; then
echo "downloading file from $sshserver."
fi
scp -v $sshuser@$sshserver:$sshpath/$file $localpath/$file &> $localpath/bandwidth_scplogdown
if [ $? -ne 0 ]; then
echo "error while downloading file. exiting."
@ -92,7 +103,9 @@ if [ $? -ne 0 ]; then
echo "cannot remove remote file. ($sshpath/$file) - you must fix this!!"
sleep 5
else
echo "remote file removed."
if [ $silent -ne 1 ]; then
echo "remote file removed."
fi
fi
exit 1
@ -108,7 +121,9 @@ if [[ $? -ne 0 ]]; then
echo "cannot remove remote file. ($sshpath/$file) - you must fix this!!"
sleep 5
else
echo "remote file removed."
if [ $silent -ne 1 ]; then
echo "remote file removed."
fi
fi
# remove local file
@ -117,10 +132,13 @@ 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."
if [ $silent -ne 1 ]; then
echo "local file has been deleted."
fi
exit 0
fi
echo "all done. exiting."
if [ $silent -ne 1 ]; then
echo "all done. exiting."
fi
exit 0