Listing 4
1: #
2: # spoolonite.sh: Version 2.0 2/27/92 by Leor Zolman
3: # Submit a job to the overnight job spooler
4: #
5: # usage:
6: # spoolonite.sh jobname [priority] <jobfile
7: # (or)
8: # spoolonite.sh jobname [priority] <<END
9: # ...
10: # END
11: #
12:
13: debug=N # if Y, use current directory for testing
14: SPOOLDIR=/usr/spool/onite # Master Overnight Spooler Directory
15: NPRIORITIES=7 # Number of priority levels
16: DEFAULT_PRIORITY=4 # If no priority given, this used by default
17: LOCKFILE=$SPOOLDIR/Onite.LOCK
18:
19: USE_CUTOFF=N # Y to use cutuff time, N for no restriction
20: CUTOFF_TIME=1955 # last call for jobs: hour and minute as hhmm
21:
22: CHECK_LOCK=Y # Y to reject requests while spooler is running
23:
24: #
25: # Make sure to list any environment variables that programs called by
26: # the user's script need to have defined, but that the user's environment
27: # itself may not have explicitly exported:
28: #
29: toexport="PATH DBDATE DBPATH DEPT DEPTO"
30:
31: [ $# -lt 1 ] && echo "usage: $0<jobname>[priority]<jobtext">&2
&& exit 1
32:
33: if [ $debug = Y ]; then
34: JOBDIR=jobs
35: else
36: JOBDIR=$SPOOLDIR/jobs
37: fi
38:
39: # Check for cutoff-time restriction:
40:
41: time=`date +%H%M`
42: if [ $USE_CUTOFF = Y -a $time -gt $CUTOFF_TIME ]; then
43: echo "Sorry, it is too late to spool a job tonight. Try again tomorrow." >&2
44: echo "(and please disregard any messages below about this job being queued!)">&2
45: exit 1
46: fi
47:
48: # Check to make sure the spooler isn't currently running:
49: if [ $CHECK_LOCK = Y -a -f $LOCKFILE ]; then
50: echo "Sorry, it is too late to spool a job tonight. Try again tomorrow." >&2
51: exit 1
52: fi
53:
54: # Make sure there is no similarly-named job already queued:
55:
56: tpr=1
57: while [ $tpr -le $NPRIORITIES ]
58: do
59: if [ -r $JOBDIR/P$tpr/$1 ]; then
60: echo "$0: job $1 already exists (priority $tpr)" >&2
61: exit 1
62: fi
63: tpr=`expr $tpr + 1`
64: done
65:
66: # Spool the jobs at the default priority, unless explicity priority was given:
67:
68: pri=$DEFAULT_PRIORITY
69: if [ $# -eq 2 ]; then # explicit priority level given; process it
70: pri=`checknum $2`
71: if [ $pri = "ERROR" -o $pri -lt 1 -o $pri -gt $NPRIORITIES ]; then
72: echo "$0: Bad priority \"$2\" (only 1-$NPRIORITIES allowed)">&2
73: exit 1
74: fi
75: fi
76:
77: JOBFILE=$JOBDIR/P$pri/$1
78: [ "$PS1" != "" ] && PS1=\"$PS1\"; export PS1 # fixes multiline
prompt bug
79: /bin/env >$JOBFILE # write environment into job file
80:
81: echo "export $toexport" >>$JOBFILE
82:
83: echo "cd `pwd`\n" >>$JOBFILE # change to current directory in job file
84: cat >>$JOBFILE # copy job text into job file
85:
86: exit 0
|