-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcosmosim-getjobids-uc.sh
62 lines (52 loc) · 1.74 KB
/
cosmosim-getjobids-uc.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
#
# Extract jobids for given job/table names.
#
# Usage: bash cosmosim-multiqueries.sh namepattern
#
# Needs uws-client:
# https://github.com/aipescience/uws-client/
# Documentation on CosmoSim's UWS interface:
# https://www.cosmosim.org/cms/documentation/data-access/access-via-uws/
#
# Author: Kristin Riebe, AIP, November 2014
if [ $# -lt 2 ]
then
echo "Please provide a pattern for tablenames and an id-file for writing."
echo "Use awk-regular expressions, e.g."
echo "^ for start, $ for end of expression, . for any character, * for repeating."
echo "Examples:"
echo " bash cosmosim-getjobids.sh bdm85 idfile.txt # match any jobname containing bdm85"
echo " bash cosmosim-getjobids.sh ^bdm85-many-1$ idfile.txt # match exactly given name"
exit
fi
username='xxusernamexx'
password='xxpasswordxx'
uws="uws"
url='https://www.cosmosim.org/uws/query'
namepattern=$1
idfile=$2
# first get complete joblist, i.e. job name, jobid and status, then filter by namepattern
cmd="$uws --host $url --user $username --password $password list"
#echo "$cmd"
joblist=`$cmd | awk '/^[^=L ]/{ if ($2 ~ /'$namepattern'/) {print $0;}}'`
echo "Jobs matching the given pattern (jobname, jobid, status): "
# -- print to terminal only
#echo "$joblist"
# -- also print ids to given file
rm -rf $idfile
touch $idfile
echo "$joblist" | awk '{print $0; printf "%d\n", $1 >> "'$idfile'"}'
if [ ! -s $idfile ]
then
echo "Sorry, no jobnames matched the given pattern '$namepattern'."
rm $idfile
else
num=`wc -l $idfile | awk '{print $1;}'`
echo "$num matching jobs found. Jobids were written to file $idfile."
fi
# or filter by status:
#status="COMPLETED"
#echo "$joblist" | awk '{if ($3 ~ /'$status'/) {print $0;}}'
#
exit