source: issm/trunk/scripts/waitonlock.sh@ 2539

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
13if [ $# -ne 2 ];
14then
15 #no config file specified: exit
16 echo "waitonlock.sh error message: bad usage"
17 exit 0
18fi
19
20#initialization
21TIME=1;
22STEP=1; #step in seconds
23FILE=$1;
24
25#check time limit
26if [ "$2" == "Inf" ]
27then
28 echo infinity detected
29 LIMIT=999999999;
30else
31 echo not inf
32 let LIMIT=$2*60;
33fi
34
35#display
36echo "waiting for $1 hold on (ctl+c to stop)..."
37
38#Loop till file is found
39while [ $TIME -lt $LIMIT ]
40do
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
53done
54
55#Compute flag
56if [ $TIME -lt $LIMIT ]; then
57 exit 1;
58else
59 exit 0;
60fi
Note: See TracBrowser for help on using the repository browser.