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