-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcosmosim-download.sh
61 lines (50 loc) · 1.73 KB
/
cosmosim-download.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
#
# Download results as csv-files for jobids read from given file
#
# Needs httpie:
# https://github.com/jkbr/httpie
# Documentation on CosmoSim's UWS interface:
# https://www.cosmosim.org/cms/documentation/data-access/access-via-uws/
#
#
# Usage: bash cosmosim-download.sh idfile
#
# NOTE: There is no error handling here, the script will break,
# if there are no results for the jobs!
#
# Author: Kristin Riebe, AIP, November 2014
if [ $# -lt 1 ]
then
echo "Please provide a filename with jobids as command line argument, e.g.:"
echo " bash cosmosim-download.sh jobids.txt"
exit
fi
username='xxusernamexx'
password='xxpasswordxx'
url='https://www.cosmosim.org/uws/query'
idfile=$1
# read file with jobids
declare -a jobidlist
jobidlist=(`less $idfile`)
numid=${#jobidlist[*]}
# If all jobs have completed, you can retrieve the results:
echo "Trying to retrieve the results. There is no proper error handling included here, so it may break easily in case of trouble."
# get result-urls and download to files
for (( i=0; i<$numid; i++ ))
do
echo
echo "Result for job ${jobidlist[$i]} ..."
cmd="http --auth ${username}:${password} GET ${url}/${jobidlist[$i]}/results"
results=`$cmd`
resulturl=`echo $results | grep csv | sed -e '' -e 's/\/csv\".*/\/csv\//g' | sed -e 's/.*xlink:href=\"//'`
if [ -z $resulturl ]
then
echo "Sorry, no result-url found. Please check the job's status manually."
echo "Use e.g. http --auth ${username}:${password} GET ${url}/${jobidlist[$i]}/phase/"
else
echo "Retrieve results for job $i (jobid ${jobidlist[$i]}) using following url: $resulturl"
http --auth ${username}:${password} --print b --download GET $resulturl
fi
done
exit