[comp.sys.sgi] At, Batch ...

doelz@urz.unibas.ch (Reinhard Doelz) (02/03/89)

Congratulations... I already thought I were a lonsome guy and nobody wants
to run batch jobs on the iris. 

The BATCH and AT commands are not reasonably documented. I tried to find
out what the queue definitions are by trial and error, and up to now
SGI did not offer any documentation on the queuedefs file. 

b.2j2n90w      means - (I believe) - the following: 

b - the queue name. You may invent any new queue name you want and you 
    may submit jobs into these queues if you specify the -q qualifier 
    in the at command. CAUTION: There is a non-documented queue c (the 
    cron queue), and any attempt to redefine this causes seriuos OS problems.

2j - the maximum jobs permitted. If the job limit is reaced, the job is 
    rescheduled later (see below). Take care not to submit too many jobs
    which are not running, otherwise your /usr/lib/cron/log file reaches
    incredible dimensions !

2n - must be something with the nice (1) command. Values up to 19 are 
    permitted. I used a different approach (see below) for prioritizing.

90w - this is the time in seconds the OS waits until it tries to reschedule
    the job. This is useful if you have log jobs running and it doesn't make
    sense to resubmit the job every minute (which is the default if the
    parameter is missing). 

My approach to redefine batch job priorities is using the non-aging 
priorities (see /usrinclude/sys/schedctl.h - thanks to SGI for giving 
the hint to look there). I added the following lines to /usr/spool/cron
/crontabs/root : 

#
# process prioritizing
15,30,45  6-22 * * * /usr/local/acct/prio_set.com
0   *   *   *   *   /usr/local/acct/prio_set.com
#

Then, I created a dirctory /usr/local/acct and put the following files there:

prio_set.com:
=============
ps -ef | awk -f /usr/local/acct/find_user.awk | awk -f 
                           /usr/local/acct/put_user.awk > /tmp/prio.csh
csh /tmp/prio.csh
rm /tmp/prio.csh

find_user.awk:
==============
{ 
n = split ($7,ti,":")
if ($7 != "?" && $1 !="root") 
print $2,ti[1],ti[2] 
}

put_user.awk:
=============
{
if ($2 > 15 && $2 < 30 && $1 != "PID") 
  print "npri -h140 -p ",$1 
if ($2 > 30 && $2 < 60 && $1 != "PID")
  print "npri -h180 -p ",$1
if ($2 > 60 && $2 < 180 && $1 != "PID")
  print "npri -h200 -p ",$1
if ($2 > 180 && $2 < 600 && $1 != "PID")
  print "npri -h220 -p ",$1
if ($2 > 600 && $2 <2000 && $1 != "PID")
  print "npri -h225 -p ",$1
if ($2 > 2000 && $1 != "PID")
  print "npri -h230 -p ",$1
}

These commands make root check every 15 minutes whether a job is to be
reprioritized, and the priority gets worse (= higher) the longer the
job is in the system. The advantage of this is that your on-line jobs 
(i.e. graphics - (NOT flight, listen, knobi?)) are not influenced by batch
jobs. 


*** PROBLEM : ***

My problem with the cron is as follows: 
If you look at the root crontab file, there is a command which makes 
cron put its output in a new logfile :
#
# rotate the logs
1   1   *   *   0   umask 033;cd /usr/lib/cron;mv -f log OLDlog;touch log; killall 1 cron

That's o.k. as long as the log file is concerned. But this new cron then 
forgot all the jobs to be scheduled and there is no way to resubmit the jobs
which are still correctly placed in /usr/spool/cron/atjobs.

Is anyone out in netland familiar with this stuff ? 

Comments, suggestions, *documentation*, etc welcome. 

Reinhard
  
  ************************************************************************
  *   Dr. Reinhard Doelz           *           SWITZERLAND               *
  *     Biocomputing               *                                     *
  *      Biozentrum                * doelz%urz.unibas.ch@relay.cs.net    *
  * Klingelbergstrasse 70          *                                     *
  *     CH-4056 Basel              *                                     *
  ************************************************************************

guy@auspex.UUCP (Guy Harris) (02/05/89)

>The BATCH and AT commands are not reasonably documented. I tried to find
>out what the queue definitions are by trial and error, and up to now
>SGI did not offer any documentation on the queuedefs file. 

The following are based on man pages I did at Sun for the "queuedefs"
and ".proto" files; they have, I think, been properly edited to document
the vanilla S5R3 versions (i.e., no SunOS changes).  You may have to
change them to reflect any SGI changes. 

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  proto.4 queuedefs.4
# Wrapped by guy@bootme on Sat Feb  4 15:06:52 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'proto.4' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'proto.4'\"
else
echo shar: Extracting \"'proto.4'\" \(2033 characters\)
sed "s/^X//" >'proto.4' <<'END_OF_FILE'
X.TH PROTO 4
X.SH NAME
Xproto \- prototype job file for at
X.SH SYNOPSIS
X.LP
X.B /usr/lib/cron/.proto
X.LP
X.BI /usr/lib/cron/.proto. queue
X.SH DESCRIPTION
X.LP
XWhen a job is submitted to
X.IR at (1)
Xor
X.IR batch (1),
Xthe job is constructed as a shell script.  First, a prologue is
Xconstructed, consisting of:
X.IP \(bu 3
XA header specifying whether the job is an
X.I at
Xjob or a
X.I batch
Xjob;
X.IP \(bu
XA set of Bourne shell commands to make the environment (see
X.IR environ (4))
Xfor the
X.I at
Xjob the same as the current environment.
X.LP
X.I at
Xthen reads a \*(lqprototype file,\*(rq and constructs the rest of the
Xjob file from it.
X.LP
XText from the prototype file is copied to the job file, except for
Xspecial \*(lqvariables\*(rq that are replaced by other text:
X.RS
X.TP
X.B $d
Xis replaced by the current working directory
X.PD 0
X.TP
X.B $l
Xis replaced by the current file size limit (see
X.IR ulimit (2))
X.TP
X.B $m
Xis replaced by the current umask (see
X.IR umask (2))
X.TP
X.B $t
Xis replaced by the time at which the job should be run, expressed as seconds
Xsince January 1, 1970, 00:00 Greenwich Mean Time, preceded by a colon
X.TP
X.B $<
Xis replaced by text read by
X.I at
Xfrom the standard input (that is, the commands provided to
X.I at
Xto be run in the job)
X.PD
X.RE
X.LP
XIf the job is submitted in queue
X.IR queue ,
X.I at
Xuses the file
X.BI /usr/lib/cron/.proto. queue
Xas the prototype file if it exists, otherwise it will use the file
X.BR /usr/lib/cron/.proto .
X.SH EXAMPLES
XThe standard
X.B .proto
Xfile supplied with System V is:
X.LP
X.RS
X.nf
X.ft B
X#ident	"@(#)adm:.proto	1.2"
Xcd $d
Xulimit $l
Xumask $m
X$<
X.ft R
X.fi
X.RE
X.LP
Xwhich causes commands to change the current directory in the job to the
Xcurrent directory at the time
X.I at
Xwas run, to change the ulimit in the job to the ulimit at the time
X.I at
Xwas run, and to change the umask in the job to the umask at the time
X.I at
Xwas run, to be inserted before the commands in the job.
X.SH FILES
X.PD 0
X.TP 20
X.B /usr/lib/cron/.proto
X.LP
X.BI /usr/lib/cron/.proto. queue
X.PD 
X.SH "SEE ALSO"
X.IR at (1)
END_OF_FILE
if test 2033 -ne `wc -c <'proto.4'`; then
    echo shar: \"'proto.4'\" unpacked with wrong size!
fi
# end of 'proto.4'
fi
if test -f 'queuedefs.4' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'queuedefs.4'\"
else
echo shar: Extracting \"'queuedefs.4'\" \(2386 characters\)
sed "s/^X//" >'queuedefs.4' <<'END_OF_FILE'
X.TH QUEUEDEFS 4
X.SH NAME
Xqueuedefs \- queue description file for at, batch, and cron
X.SH SYNOPSIS
X.LP
X.B /usr/lib/cron/queuedefs
X.SH DESCRIPTION
X.LP
XThe
X.B queuedefs
Xfile describes the characteristics of the queues managed by
X.IR cron (1M).
XEach non-comment line in this file describes one queue.
XThe format of the lines are as follows:
X.RS
X.LP
X\fIq\fB.\fR[\fInjob\fBj\fR][\fInice\fBn\fR][\fInwait\fBw\fR]
X.RE
X.LP
XThe fields in this line are:
X.RS
X.TP
X.I q
XThe name of the queue.
X.B a
Xis the default queue for jobs started by
X.IR at (1);
X.B b
Xis the default queue for jobs started by
X.I batch
X(see
X.IR at (1));
X.B c
Xis the default queue for jobs run from a
X.IR crontab (4)
Xfile.
X.TP
X.I njob
XThe maximum number of jobs that can be run simultaneously in that queue; if
Xmore than
X.I njob
Xjobs are ready to run, only the first
X.I njob
Xjobs will be run, and the others will be run as jobs that are currently running
Xterminate.  The default value is 100.
X.TP
X.I nice
XThe
X.IR nice (1)
Xvalue to give to all jobs in that queue that are not run with a user
X.SM ID
Xof super-user.  The default value is 2.
X.TP
X.I nwait
XThe number of seconds to wait before rescheduling a job that was deferred
Xbecause more than
X.I njob
Xjobs were running in that job's queue, or because more than 25 jobs were
Xrunning in all the queues.  The default value is 60.
X.RE
X.LP
XLines beginning with
X.B #
Xare comments, and are ignored.
X.SH EXAMPLE
X.RS
X.nf
X.ft B
Xa.4j1n
Xb.2j2n90w
X.RE
X.fi
X.ft R
X.LP
XThis file specifies that the
X.B a
Xqueue, for
X.I at
Xjobs, can have up to 4 jobs running simultaneously; those jobs will be run with
Xa
X.B nice
Xvalue of 1.  As no
X.I nwait
Xvalue was given, if a job cannot be run because too many other jobs are running
X.I cron
Xwill wait 60 seconds before trying again to run it.
XThe
X.B b
Xqueue, for
X.I batch
Xjobs, can have up to 2 jobs running simultaneously; those jobs will be run with
Xa
X.I nice
Xvalue of 2.  If a job cannot be run because too many other jobs are running,
X.I cron
Xwill wait 90 seconds before trying again to run it.
XAll other queues can have up to 100 jobs running simultaneously; they will be
Xrun with a
X.I nice
Xvalue of 2, and if a job cannot be run because too many other jobs are running
X.I cron
Xwill wait 60 seconds before trying again to run it.
X.SH FILES
X.PD 0
X.TP 20
X.B /usr/lib/cron/queuedefs
X.PD 
X.SH "SEE ALSO"
X.IR at (1),
X.IR nice (1),
X.IR crontab (4),
X.IR cron (1M)
END_OF_FILE
if test 2386 -ne `wc -c <'queuedefs.4'`; then
    echo shar: \"'queuedefs.4'\" unpacked with wrong size!
fi
chmod +x 'queuedefs.4'
# end of 'queuedefs.4'
fi
echo shar: End of shell archive.
exit 0