Hi all,
I was asked to explain parts of the script below, and in case there
are others that are interested, I've decide to make my reply public.
Also, I wrote that 7.0+ was needed to run the script below, but that
is incorrect. I think you just need 6.0 exp 1 or later.
...
> PARM acct=!hpaccount
> # This script displays all jobs that match the specified account
> #
--> CI comments can begin with a '#' just like a unix shell.
> setvar _sj_acct ups("!acct")
--> I upshift the account name for display purposes only. The JOBCNT
function works fine with lowercase.
> if setvar(_sj_cnt, JOBCNT("@j:@.!_sj_acct",_sj_jobs)) = 0 then
--> I invoke the relatively new JOBCNT function. Try HELP JOBCNT on
your system to see if you have it. There is an article on JOBCNT
on our Jazz webserver at:
http://jazz.external.hp.com/papers/Communicator/6.0/exp1/ci_enhancements.htm
l
(watch line wrap)
So, if there are more than zero jobs currently running (or waiting or
scheduled) then the return from JOBCNT will be > 0 and we want to
process them. Last, the matching job numbers (J123, etc) are stored
in the CI variable names "_sj_jobs" with one space in between each
job number.
> echo No jobs found in the !_sj_acct
> return
> endif
> echo !_sj_cnt jobs in the !_sj_acct found...
> setvar _sj_i 0
> while setvar(_sj_job,word(_sj_jobs," ",setvar(_sj_i,_sj_i+1))) <> "" do
--> parse the _sj_jobs variable extracting out each separate number (token)
which in this case is delimited by a space. Before the extraction (done
by the WORD function (help WORD)) increment the word index argument. So,
we get the 1st job number, then the second (_sj_i+1) job number, then
the
3rd... until we hit the end of the variable value (when the return from
WORD is "" (empty)).
> # display info about this job
> setvar _sj_buf "!_sj_job "+JINFO(_sj_job,"JobUserAccountGroup")+" "+&
> JINFO(_sj_job,"FmtIntroDate") + " " + &
> JINFO(_sj_job,"JobState")
--> create a string variable that contains the matching job number,
followed by the "Jobname,UserName.AcctName,GroupName", followed
by the date the job was introduced, followed by the job's state:
EXEC, SUSP, SCHED, INTRO. These fields will not be aligned in
the output since each field is variable width. To get the fields
in columns use the RPT function to insert a variable number of
blanks based on the actual width of the data being echoed.
> echo !_sj_buf
> endwhile
> if _sj_cnt > WORDCNT(_sj_jobs) then
--> The JOBCNT function may not be able to store all of the matching
job numbers in the _sj_jobs variable, since a CI string variable
is limited to 1024 bytes. However, JOBCNT always returns the
total number of matching jobs, not the number of entries that
fit into the variable. To detect the (hopefully small number of)
cases when the variable was not able to hold all of the
matching jobs I use the WORDCNT function. This function returns
the number of tokens in a string, so it will return the number of
jobs that fit in the _sj_jobs variable. If this differs from
the function return from JOBCNT then you know that there has
been truncation. The solution to this is usually to further
restrict the criteria JOBCNT uses to select matching entries.
> echo some jobs could not be displayed, try again...
> endif
HTH,
Jeff Vance, vCSY
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|