-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqst
executable file
·68 lines (59 loc) · 1.72 KB
/
qst
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
62
63
64
65
66
67
68
#!/usr/bin/bash
# Function to display usage
usage() {
echo "Usage: $0 <status> [-n <number_of_jobs>] [search_string]"
echo "status: 'r' for running, 'q' for queued jobs or 'f' for finished jobs (mandatory)"
echo "-n <number_of_jobs>: optional, the number of jobs to display (default: 20)"
echo "[search_string]: optional, a string to search for in the job details"
exit 1
}
# Check if the first argument (status) is provided
if [ -z "$1" ]; then
usage
fi
# Convert lowercase status to uppercase and assign to STATUS variable
STATUS=$(echo "$1" | tr '[:lower:]' '[:upper:]')
# Shift to the next argument
shift
# Default value for the number of jobs
NUM_JOBS=40
# Parse optional arguments
while getopts ":n:" opt; do
case $opt in
n)
NUM_JOBS="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
# Shift to the next argument after the options
shift $((OPTIND - 1))
# Assign the remaining argument (if any) to SEARCH_STRING
SEARCH_STRING="${1:-}"
# Fetch JSON data and process it with jq
qsjs jupiter | jq --arg status "$STATUS" --argjson num_jobs "$NUM_JOBS" --arg search_string "$SEARCH_STRING" '
.jobs |
map(select(
.status == $status and
.owner == "vport@ufsc" and (
($search_string == "" or (
(.id // "" | test($search_string; "i")) or
(.name // "" | test($search_string; "i")) or
(.pwd // "" | test($search_string; "i")) or
(.node // "" | test($search_string; "i")) or
(.queue // "" | test($search_string; "i")) or
(.walltime // "" | test($search_string; "i"))
))
)
)) |
reverse |
.[:$num_jobs] |
reverse
'