Last change
on this file since 2539 was 2539, checked in by Mathieu Morlighem, 15 years ago |
Added waitonlock.sh, might be used on clusters
|
-
Property svn:executable
set to
*
|
File size:
1.0 KB
|
Line | |
---|
1 | #!/bin/bash
|
---|
2 | #script version of waitonlock.m
|
---|
3 | #function flag=waitonlock(filename,timelimit)
|
---|
4 | #%WAITONLOCK - wait for a file
|
---|
5 | #%
|
---|
6 | #% This routine will return when a file named 'filename' is written to disk.
|
---|
7 | #% If the time limit given in input is exceeded, return 0
|
---|
8 | #%
|
---|
9 | #% Usage:
|
---|
10 | #% flag=waitonlock(filename,timelimit)
|
---|
11 |
|
---|
12 | #Check input value
|
---|
13 | if [ $# -ne 2 ];
|
---|
14 | then
|
---|
15 | #no config file specified: exit
|
---|
16 | echo "waitonlock.sh error message: bad usage"
|
---|
17 | exit 0
|
---|
18 | fi
|
---|
19 |
|
---|
20 | #initialization
|
---|
21 | TIME=1;
|
---|
22 | STEP=1; #step in seconds
|
---|
23 | FILE=$1;
|
---|
24 |
|
---|
25 | #check time limit
|
---|
26 | if [ "$2" == "Inf" ]
|
---|
27 | then
|
---|
28 | echo infinity detected
|
---|
29 | LIMIT=999999999;
|
---|
30 | else
|
---|
31 | echo not inf
|
---|
32 | let LIMIT=$2*60;
|
---|
33 | fi
|
---|
34 |
|
---|
35 | #display
|
---|
36 | echo "waiting for $1 hold on (ctl+c to stop)..."
|
---|
37 |
|
---|
38 | #Loop till file is found
|
---|
39 | while [ $TIME -lt $LIMIT ]
|
---|
40 | do
|
---|
41 |
|
---|
42 | #lock file exists?
|
---|
43 | if [ -e $FILE ]; then
|
---|
44 | break;
|
---|
45 | fi
|
---|
46 |
|
---|
47 | #No-> wait one second
|
---|
48 | sleep $STEP
|
---|
49 | let TIME+=1;
|
---|
50 | echo "waiting $TIME seconds ($TIME < $LIMIT)"
|
---|
51 | dummy=$(ls); #force bash to refresh file list
|
---|
52 |
|
---|
53 | done
|
---|
54 |
|
---|
55 | #Compute flag
|
---|
56 | if [ $TIME -lt $LIMIT ]; then
|
---|
57 | exit 1;
|
---|
58 | else
|
---|
59 | exit 0;
|
---|
60 | fi
|
---|
Note:
See
TracBrowser
for help on using the repository browser.