BRIAN@UOFT02.BITNET (Brian Nelson) (06/30/88)
Regarding the previous question about spawning from detached processes
to create batch jobs, I thought it might be of some use to supply an
example of using $SNDJBC. The code is taken from a bitnet file server
of the authors.
Brian Nelson
U of Toledo
/*
Sendbatch() submits a batch job to a queue. The queue is, guess what,
specified by the logical 'HOOK_NAME'_BATCH_QUEUE at startup, ie for a
hook called VMSSERV, it uses VMSSERV_BATCH_QUEUE. Ditto for the username
to submit the job under, for a hook called VMSSERV its
VMSSERV_BATCH_USERNAME. Note again, please, that these logicals do have
defaults, which are hardcoded in the image (see comments at the start of
this file), and that these logicals are set up in Generate_logicals().
\BDN
Passed: F char*, pointer to the filename.type to submit
LATE int , flag to specify deferred submission
PARAMS char **, pointers to paramaters. Ie, the caller could
declare an array and set up pointers to P1,P2, ...P8.
The Nth+1 entry MUST point to a null string.
char *parameters[3]
paramaters[0] = "This is P1"
paramaters[1] = "This is P2"
paramaters[2] = ""
Return: System service status
*/
sendbatch(f,late,params)
char *f,**params ;
int late ;
{
#define SJC$_AFTER_TIME 3
#define SJC$_ENTER_FILE 19
#define SJC$_QUEUE 134
#define SJC$_FILE_SPECIFICATION 42
#define SJC$_LOG_SPECIFICATION 98
#define SJC$_NO_LOG_SPOOL 101
#define SJC$_NO_DELETE_FILE 25
#define SJC$_USERNAME 159
#define SJC$_NO_PAGINATE 118
#define SJC$_PARAMETER_1 119
#define SJC$_PARAMETER_2 120
#define SJC$_PARAMETER_3 121
#define SJC$_PARAMETER_4 122
#define SJC$_PARAMETER_5 123
#define SJC$_PARAMETER_6 124
#define SJC$_PARAMETER_7 125
#define SJC$_PARAMETER_8 126
#define SJC$_NO_PARAMETERS 127
struct itmlst {
short int buflen;
short int code ;
char *bufadr ;
int *retlen ;
} ;
$DESCRIPTOR(latetime,"-- 23:00:00.00") ;
static struct itmlst dobatch[20] ;
int i,status,iosb[2],abstime[2],*ip ;
int params_code[] = {SJC$_PARAMETER_1,SJC$_PARAMETER_2,
SJC$_PARAMETER_3,SJC$_PARAMETER_4,
SJC$_PARAMETER_5,SJC$_PARAMETER_6,
SJC$_PARAMETER_7,SJC$_PARAMETER_8,
0 } ;
sys$bintim(&latetime,&abstime) ;
i = 0 ;
dobatch[i].buflen = strlen(batch_queue) ;
dobatch[i].code = SJC$_QUEUE ;
dobatch[i].bufadr = batch_queue ;
dobatch[i++].retlen = 0 ;
dobatch[i].buflen = strlen(f) ;
dobatch[i].code = SJC$_FILE_SPECIFICATION ;
dobatch[i].bufadr = f ;
dobatch[i++].retlen = 0 ;
dobatch[i].buflen = 0 ;
dobatch[i].code = SJC$_NO_LOG_SPOOL ;
dobatch[i].bufadr = 0 ;
dobatch[i++].retlen = 0 ;
dobatch[i].buflen = strlen(batch_username) ;
dobatch[i].code = SJC$_USERNAME ;
dobatch[i].bufadr = batch_username ;
dobatch[i++].retlen = 0 ;
dobatch[i].buflen = strlen(scratch_dir) ;
dobatch[i].code = SJC$_LOG_SPECIFICATION ;
dobatch[i].bufadr = scratch_dir ;
dobatch[i++].retlen = 0 ;
for ( ip=params_code ; **params ; i++ ) {
if ( *ip == 0 ) break ;
dobatch[i].buflen = strlen( *params ) ;
dobatch[i].code = *ip++ ;
dobatch[i].bufadr = *params++ ;
dobatch[i].retlen = 0 ;
} ;
if (late) {
dobatch[i].buflen = 8 ;
dobatch[i].code = SJC$_AFTER_TIME ;
dobatch[i].bufadr = &abstime ;
dobatch[i++].retlen = 0 ;
} ;
dobatch[i].buflen = 0 ;
dobatch[i].code = 0 ;
status = sys$sndjbcw(0,SJC$_ENTER_FILE,0,&dobatch,&iosb,0,0) ;
return(iosb[0]) ;
}
create_batch_job(cmds,late,params)
char **cmds,**params ;
int late ;
{
FILE *fp ;
char *cp,msg[256] ;
int status ;
cp = xmalloc(256) ;
sprintf(cp,"%s%s.COM",scratch_dir,tmpnam(0)) ;
if ( (fp = fopen(cp,"w")) == NULL ) {
sprintf(msg,"Create_batch: Failure on creating %s\n",cp);
sendlogfile(msg);
return(0) ;
} ;
fprintf(fp,"$ SET NOON\n") ;
while (*cmds != 0 ) fprintf(fp,"%s\n",*cmds++) ;
if ( !( *test_mode == 'Y' || *test_mode == 'y' ) )
fprintf(fp,"$ if $STATUS then delete %s.\n",cp) ;
fclose(fp) ;
if ( ((status = sendbatch(cp,late,params)) & 1) == 0 )
report_error("Create_batch: Error in calling SENDBATCH",status) ;
xfree(cp) ;
return( status ) ;
}