-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathswitch_part.sh
More file actions
executable file
·79 lines (69 loc) · 2.41 KB
/
switch_part.sh
File metadata and controls
executable file
·79 lines (69 loc) · 2.41 KB
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
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
##This script transfers pending jobs from one SLURM partition to another.
##The user can specify how many jobs to transfer. To transfer all pending jobs, set -n 0.
##Currently, only pending jobs of the logged in user's netid is used.
##Currently, the specific jobs to be transferred are arbitrary picked from the top of the squeue -t PD list.
usage="Usage: switch_part.sh -n [NUMBER_OF_JOBS_TO_TRANSFER] -f [TRANSFER_FROM] -p [TRANSFER_TO]"
##-f is optional. If omitted, the pending jobs from all partitions will be transferred.
netid=$USER
#Argument processing.
while getopts :n:f:p: option; do
case $option in
n)
numjobs=$OPTARG
;;
p)
transferto=$OPTARG
;;
f)
transferfrom=$OPTARG
;;
\?)
echo "Error: -$OPTARG is not a valid option." >&2
echo $usage >&2
exit 1;
;;
:)
echo "Error: -$OPTARG requires an argument." >&2
echo $usage >&2
exit 1;
;;
esac
done
if [ -o $numjobs ]; then
echo "The parameter -n (number of jobs) is required." >&2
exit 1;
fi
if [ -o $transferto ]; then
echo "The parameter -p (partition to transfer to) is required." >&2
exit 1;
fi
#Run squeue, depending on whether -f is supplied. Store in joblist.
if [ ! -o $transferfrom ]; then
joblist=`squeue -r -u $netid -h -t PD -p $transferfrom -o \%i`
else
joblist=`squeue -r -u $netid -h -t PD -o \%i`
fi
#Set a flag for the number of jobs transferred.
transferred=0
#Loop over joblist and transfer.
for job in $joblist; do
#If we have exceeded the number of jobs to be transferred, break out of the for loop.
#When $numjobs is 0, transfer all pending jobs.
if [[ $numjobs != 0 ]] && [[ $transferred -ge $numjobs ]] ; then
break
fi
scontrol update jobid=$job partition=$transferto
#Increment the jobs transferred number.
transferred=$(($transferred+1))
done
#Print a warning if the number of jobs to be transferred is different from the number actually transferred.
if [ $numjobs -eq 0 ]; then
echo "Transferred all pending jobs ($transferred) to $transferto."
elif [ $transferred -lt $numjobs ]; then
echo "Warning: Requested that $numjobs get transferred to $transferto, but only transferred $transferred. There were probably fewer than $numjobs pending."
elif [ $transferred -lt $numjobs ]; then
echo "Warning: Requested that $numjobs get transferred to $transferto, but transferred $transferred. Is there an error in the arguments supplied?"
else
echo "Transferred $numjobs to $transferto."
fi