-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdq-tail
executable file
·51 lines (39 loc) · 1.06 KB
/
dq-tail
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
D=$(cd `dirname $0` && pwd)
BDIR=$D/jobs/backend
SSH="ssh -q -x -o BatchMode=yes -o ConnectTimeout=10 -o ServerAliveInterval=3"
jobspec="$1"
shift
tailargs="$@"
if [ "x$jobspec" = "x" ]; then
jobspec=$USER
fi
BJOBS=$(ls -1 $BDIR | grep "^$jobspec-")
BCNT=$(echo "$BJOBS" | grep . | wc -l)
if [ $BCNT -eq 0 ]; then
BJOBS=$(ls -1 $BDIR | grep "^$jobspec")
BCNT=$(echo "$BJOBS" | grep . | wc -l)
if [ $BCNT -eq 0 ]; then
BJOBS=$(ls -1 $BDIR | grep "$jobspec")
BCNT=$(echo "$BJOBS" | grep . | wc -l)
fi
fi
if [ $BCNT -gt 1 ]; then
echo "Ambiguous job specification '$jobspec'. Multiple possibilities:"
echo "$BJOBS"
exit 1
fi
if [ $BCNT -eq 1 ]; then
JOBID=$BJOBS
JOBDIR=$BDIR/$JOBID
U=$(cat $JOBDIR/user.txt)
H=$(cat $JOBDIR/host.txt)
if ! flock -nx $JOBDIR/lock true; then
echo "Flushing logs of $JOBID"
KRB5CCNAME=$JOBDIR/ticket.krb5 $SSH -t $U@$H screen -S dq-$JOBID -X colon "logfile flush 1
"
fi
tail $tailargs $JOBDIR/screenlog.0
exit 0
fi
echo "Could not find matching job for '$jobspec'"