Commit 3fe03d81 authored by Reto Da Forno's avatar Reto Da Forno

shell tool updated

parent 5fed5c9c
......@@ -2,7 +2,7 @@
#
# ------------------------------
# Command line tool for FlockLab
# v1.1
# v1.2
#
# Usage:
#
......@@ -22,7 +22,7 @@
# ------------------------------
DEST=/tmp # destination directory
EXTRACT=0 # extract results?
EXTRACT=1 # extract results?
TESTCONFIG=0 # also download XML test config?
SERVER_URL=https://www.flocklab.ethz.ch/user
CURL_PARAMS='-sS -4'
......@@ -96,7 +96,7 @@ password $PASSWORD" > $NETRC_FILE
if [ -d $DEST/$TESTID ]
then
echo "Error: directory $DEST/$TESTID already exists"
exit
exit 1
fi
mkdir $DEST/$TESTID
$DAV_CLIENT > $DEST/$TESTID/dav.log 2>&1 <<EOF
......@@ -131,7 +131,7 @@ EOF
if [ "$#" -lt 1 ]
then
usage
exit
exit 1
fi
while getopts “v:c:a:d:f:g:h” OPTION
......@@ -144,17 +144,19 @@ do
if [ `echo $RESPONSE | wc -m` -lt 2 ]
then
password
exit
exit 1
fi
SUCCESS=`echo $RESPONSE | sed '/<p>The file validated correctly.<\/p>/!d' | wc -l`
if [ $SUCCESS -eq 0 ]
then
echo $RESPONSE | sed 's/.*<!-- cmd -->\(.*\)<!-- cmd -->.*/\1/;s/<li>/\n/g;s/<[^>]*>//g'
exit 1
else
echo 'The file validated correctly.'
fi
else
echo 'There were connection problems contacting the FlockLab server '$SERVER_URL
exit 1
fi
;;
c)
......@@ -164,17 +166,19 @@ do
if [ `echo $RESPONSE | wc -m` -lt 2 ]
then
password
exit
exit 1
fi
SUCCESS=`echo $RESPONSE | sed '/<!-- cmd --><p>Test (Id [0-9]*) successfully added.<\/p>/!d' | wc -l`
if [ $SUCCESS -eq 0 ]
then
echo $RESPONSE | sed 's/.*<!-- cmd -->\(.*\)<!-- cmd -->.*/\1/;s/<li>/\n/g;s/<[^>]*>//g'
exit 1
else
echo $RESPONSE | sed 's/.*<!-- flocklabscript\,\([0-9]*\),\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}+[0-9]\{4\}\),\([0-9]*\)-->.*/Test successfully added. Test ID: \1, Starttime: \2 (\3)/'
fi
else
echo 'There were connection problems contacting the FlockLab server '$SERVER_URL
exit 1
fi
;;
a)
......@@ -184,17 +188,19 @@ do
if [ `echo $RESPONSE | wc -m` -lt 2 ]
then
password
exit
exit 1
fi
SUCCESS=`echo $RESPONSE | sed '/<!-- cmd --><p>The test has been aborted.<\/p><!-- cmd -->/!d' | wc -l`
if [ $SUCCESS -eq 0 ]
then
echo $RESPONSE | sed 's/.*<!-- cmd -->\(.*\)<!-- cmd -->.*/\1/;s/<li>/\n/g;s/<[^>]*>//g'
exit 1
else
echo $RESPONSE | sed 's/.*<!-- cmd --><p>\(The test has been aborted\.\)<\/p><!-- cmd -->.*/\1/'
fi
else
echo 'There were connection problems contacting the FlockLab server '$SERVER_URL
exit 1
fi
;;
d)
......@@ -204,24 +210,26 @@ do
if [ `echo $RESPONSE | wc -m` -lt 2 ]
then
password
exit
exit 1
fi
SUCCESS=`echo $RESPONSE | sed '/<!-- cmd --><p>The test has been removed.<\/p><!-- cmd -->/!d' | wc -l`
if [ $SUCCESS -eq 0 ]
then
echo $RESPONSE | sed 's/.*<!-- cmd -->\(.*\)<!-- cmd -->.*/\1/;s/<li>/\n/g;s/<[^>]*>//g'
exit 1
else
echo $RESPONSE | sed 's/.*<!-- cmd --><p>\(The test has been removed\.\)<\/p><!-- cmd -->.*/\1/'
fi
else
echo 'There were connection problems contacting the FlockLab server '$SERVER_URL
exit 1
fi
;;
g)
echo "Fetching results for test $OPTARG ..."
OUTFILE=$DEST/$OPTARG.tar.gz
RESPONSE=`curl -o - $CURL_PARAMS -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "testid=${OPTARG}&query=get&username=${USER}&password=${PASSWORD}" $SERVER_URL/login.php -o $OUTFILE $SERVER_URL/result_download_archive.php`
FILESIZE=`stat --printf="%s" $OUTFILE`
RESPONSE=`curl $CURL_PARAMS -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "testid=${OPTARG}&query=get&username=${USER}&password=${PASSWORD}" -o $OUTFILE $SERVER_URL/result_download_archive.php`
FILESIZE=`stat -c "%s" $OUTFILE`
if [ $FILESIZE -lt 1000 ]
then
OUTFILECONT=`cat $OUTFILE`
......@@ -229,7 +237,7 @@ do
then
ERRORMSG=`echo ${OUTFILECONT:1:-1} | awk -F':' '{print $3}'`
echo "Failed: "$ERRORMSG
rm
rm $OUTFILE
exit 1
fi
fi
......@@ -250,7 +258,7 @@ do
else
OUTFILE=$DEST/${OPTARG}_config.xml
fi
RESPONSE=`curl -o - $CURL_PARAMS -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "testid=${OPTARG}&query=get&username=${USER}&password=${PASSWORD}" $SERVER_URL/login.php -o $OUTFILE $SERVER_URL/testconfig_download.php`
RESPONSE=`curl $CURL_PARAMS -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "testid=${OPTARG}&query=get&username=${USER}&password=${PASSWORD}" -o $OUTFILE $SERVER_URL/testconfig_download.php`
fi
;;
f)
......@@ -265,11 +273,11 @@ do
;;
h)
usage
exit
exit 0
;;
?)
usage
exit
exit 0
;;
esac
done
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment