forked from cdt-data-science/cluster-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
killmyjobs
executable file
·51 lines (45 loc) · 1.54 KB
/
killmyjobs
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
#!/bin/bash
running_only=false
print_usage () {
cat << EOM
Usage: $0 [-n nodelist] [-g] [-e JOBID [-e JOBID ... ]]
Kills all your jobs! By default, also kills those you have queued up too.
To only kill your running jobs, use the -g flag.
Jobs that are not to be killed can be indicated using the -e flag.
Arguments:
-n (optional) specify nodes, either comma separated list, or summarised.
Mirrors slurm command -n usage in sinfo, and -w usage for squeue."
-g (optional) will only kill running jobs, not jobs in the queue
-e (optional) a job to exclude, can specify multiple times
EOM
}
while getopts 'n:ge:' flag; do
case "${flag}" in
n) nodes="${OPTARG}" ;;
g) running_only=true ;;
e) exclude+=("$OPTARG") ;;
*) print_usage
exit 1 ;;
esac
done
if [ "$running_only" = true ]; then
if [ -z ${nodes+x} ]; then
nodes=`sinfo --format="%N" --noheader`
fi
echo "not killing jobs in queue"
jobids="$(squeue -u `whoami` --nodelist=${nodes} -o "%i" --noheader | LC_ALL=C sort)"
else
echo "killing jobs in queue as well as running jobs"
jobids="$(squeue -r -u `whoami` -o "%i" --noheader | LC_ALL=C sort)"
fi
if [[ -n ${exclude+1} ]]; then
echo "excluding ${exclude[@]}"
excl=`printf '%s\n' "${exclude[@]}" | LC_ALL=C sort`
jobids=`comm -13 <(echo "$excl") <(echo "$jobids") | tr '\n' ' '`
fi
if [ "${jobids}" = "" ]; then
echo "well I would...but you've got no jobs to kill m8"
else
echo "killing $jobids"
parallel 'scancel {}' ::: ${jobids}
fi