Duy Dinh - 2012-03-12
 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
#!/bin/bash
# Deletes all jobs submitted to OSIRIM platform  
 # given the starting job ID
# Duy Dinh, IRIT - University of Toulouse, March. 2012
#
# Syntax:
# $sh deleteJobQueue.sh startJobId
#

startJobID=$1

if (test $# -eq 0)
then   
    echo "Start JobID must be specified!"
    exit
else
    echo "Deleting jobs after JobID $startJobID"
fi


# value returned by the split function
arr=();

# split a string with a set of delimiters
split()
{
    saveIFS=$IFS
    IFS="$2" # delimiter
    arr=($1) # convert string to arrays of strings delimited by a set of delimeters
    IFS=$saveIFS
}

# run qstat, get first (jobID) and third (user name) column
str=$(
        /opt/pbs/bin/qstat |
        awk 'BEGIN { OFS = ";"; ORS = "\n" } {print $1,$3}'
    )

# convert to array of elements
elements=($str)

i=0
while [ $i -lt ${#elements[@]} ]
do
    s=${elements[$i]}
    split $s ';'
#   echo ${arr[1]}
    if test ${arr[1]} = ${USER}
    then
        #echo "${arr[0]} ${arr[1]}"
        split ${arr[0]} '.'
        if [[ ${arr[0]} -gt $startJobID ]]
        then            
            echo "Deleting job " ${arr[0]}
            /opt/pbs/bin/qdel ${arr[0]}
        fi
    fi

    (( i=i+1 ))
done

sleep 1
/opt/pbs/bin/qstat
 

Last edit: Duy Dinh 2013-12-05