Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

Help in Script Execution

 
Adil Usmani
Occasional Visitor

Help in Script Execution

Hi Members !

I have made my first script in DCL (open VMS).

I want to schedule it, please see the below script & help me in this regard.

Thanks ...

============================================
$
$! SCRIPT FOR CALCULATING SMSC 24 HOUR STATS
$
$ DEFAULT_RUNPERIOD_CHANGED = "NO" ! if set to "YES", please configure your own runperiod in the next line
$ runperiod = "00:00:09"
$
$ set verify ! for debugging
$ dclname = f$environment("PROCEDURE")
$
$ say := write sys$output
$ NODENAME = f$getsyi("NODENAME")
$ NODENAME = f$extract(0,5,NODENAME) + "1"
$ FILE_LOCATION = "SMSC_TRC0:[STATS]"
$ if f$search("''f$extract(0,8,FILE_LOCATION)'[000000]stats.dir") .eqs. ""
$ then
$ create /dir 'FILE_LOCATION'
$ endif
$
$!***RESUBMIT JOB
$ if DEFAULT_RUNPERIOD_CHANGED .eqs. "NO"
$ THEN
$ now_time = f$time()
$ now_min = f$integer(f$cvtime(,, "MINUTE"))
$
$ next_min = "00"
$ if (09 - f$integer(now_min) .GT. 0) .AND. (next_min .EQS. "00") then next_min = "0:09"
$ if (19 - f$integer(now_min) .GT. 0) .AND. (next_min .EQS. "00") then next_min = "0:19"
$ if (29 - f$integer(now_min) .GT. 0) .AND. (next_min .EQS. "00") then next_min = "0:29"
$ if (39 - f$integer(now_min) .GT. 0) .AND. (next_min .EQS. "00") then next_min = "0:39"
$ if (49 - f$integer(now_min) .GT. 0) .AND. (next_min .EQS. "00") then next_min = "0:49"
$ if (59 - f$integer(now_min) .GT. 0) .AND. (next_min .EQS. "00") then next_min = "0:59"
$ if (59 - f$integer(now_min) .EQ. 0) .AND. (next_min .EQS. "00") then next_min = "1:09"
$
$ runperiod_min = "0" + next_min + ":00"
$ next_time = f$cvtime(f$element(0,":",now_time)+ "+0-" + ''runperiod_min',"ABSOLUTE")
$ ELSE
$ next_time = f$cvtime("''now_time'+0-''runperiod'","ABSOLUTE")
$ ENDIF
$
$ submitcmd = "SUBMIT/RESTART/NOPRINT/QUEUE=''NODENAME'_BATCH/LOG=''FILE_LOCATION'STATS.LOG ''dclname'"
$ 'submitcmd' /AFTER="''next_time'"
$
$! Send PML COMMANDS
$! =================================================================================================
$! OUTPUT PARAMETERS:
$!Construct PML Commands File
$
$ create 'FILE_LOCATION'smh_stat.pml
$ open /write /error=SEND_PML PMLFILE 'FILE_LOCATION'smh_stat.pml
$ write PMLFILE "CONNECT"
$ write PMLFILE "ENABLE OUTPUT /FILE=" + FILE_LOCATION + "smh_stat.txt"
$ write PMLFILE "time"
$ write PMLFILE "show class smh /sm_rec/sm_trans /notif_trans"
$ write PMLFILE "show class smh /msg_buff"
$ write PMLFILE "DISCONNECT"
$ write PMLFILE "EXIT"
$ close PMLFILE
$ pml_script = FILE_LOCATION + "smh_stat.pml"
$
$ SEND_PML:
$ pml := $smsc$root:[bin]pml
$ define/user sys$output nla0:
$ pml/input_file='pml_script'/queue=send_pml_command/response_time=60
$
$
$! Calculate Values
$! ====================================================================================
$ TOTAL_SMTRANS = 0
$ TOTAL_NOTIFTRANS = 0
$ NUM_SMTRANS = "0"
$ NUM_NOTIFTRANS = "0"
$
$ Check_VALUES:
$ NUM_SMH = 0
$ open/read/error=VALUES_ERROR seqfp 'FILE_LOCATION'smh_stat.txt
$
$ VALUES_LOOP:
$ read/end=VALUES_ERROR seqfp LINE
$
$ if F$EXTRACT (24,26,LINE) .eqs. "Transmitted short messages"
$ THEN
$ NUM_SMH = NUM_SMH + 1
$ NUM_SMTRANS = F$ELEMENT(1,":", LINE)
$ TOTAL_SMTRANS = F$INTEGER(NUM_SMTRANS) + TOTAL_SMTRANS
$ endif
$
$ if F$EXTRACT (25,25,LINE) .eqs. "Transmitted notifications"
$ THEN
$ NUM_SMH = NUM_SMH + 1
$ NUM_NOTIFTRANS = F$ELEMENT(1,":", LINE)
$ TOTAL_NOTIFTRANS = F$INTEGER(NUM_NOTIFTRANS) + TOTAL_NOTIFTRANS
$ endif
$
$ if NUM_SMH .ne. 2*TOTAL_NUM_SMH THEN goto VALUES_LOOP
$ close seqfp
$
$ VALUES_ERROR:
$
$ STR_DATA = STR_DATA + f$string(TOTAL_SMTRANS/60) + "," + f$string(TOTAL_NOTIFTRANS/60)
$
$! ==================================================================================
$! WRITE TO FILE
$! ==================================================================================
$
$ STR_DAY = f$cvtime(,,"DAY")
$ STR_MONTH = f$cvtime(,,"MONTH")
$ STR_YEAR = f$cvtime(,,"YEAR")
$ NEW_FILENAME = "SMPN91_" + STR_YEAR + STR_MONTH + STR_DAY + ".unl"
$
$ WRITEDATA:
$ open /append /error=WRITEDATA_ERROR WRFILE 'FILE_LOCATION''NEW_FILENAME'
$ FILE_EXIST_FLAT = "true"
$ write WRFILE STR_DATA
$ close WRFILE
$
$ WRITEDATA_ERROR:
$ if FILE_EXIST_FLAT .eqs. "false"
$ then
$ create 'FILE_LOCATION''NEW_FILENAME'
$ open /append WRFILE 'FILE_LOCATION''NEW_FILENAME'
$ write WRFILE NODENAME
$ write WRFILE "Rx,Tx,Notif,Total,Buff0,Buff1"
$ close WRFILE
$ goto WRITEDATA
$ endif
$
$
$! Delete Unwanted Files
$! =================================================================================================
$ delete 'FILE_LOCATION'smh_stat.txt;*
$ delete 'FILE_LOCATION'smh_stat.pml;*
$ delete 'FILE_LOCATION'STATS.LOG;*
$ set noverify
7 REPLIES 7
John Gillings
Honored Contributor

Re: Help in Script Execution

Adil,

I'm not sure what the question is!

What are you trying to achieve?

What errors or problems are you seeing?

If I've read it correctly, you're trying to round up times to the next 9 minutes? If so, you can replace your block of IF statements with something like:

$ next=F$INTEGER(now_min+1)/10*10+9
$ hrs=next/60
$ next_min=F$FAO("!2ZL:!2ZL",hrs,my_min-hrs*60)

I'd also recommend changing

$ dclname = f$environment("PROCEDURE")

to

$ dclname = f$parse(";",f$environment("PROCEDURE"))

this drops the explicit version number from the filespec, so the latest version of the procedure is used.

If this doesn't help, please post more detail about your problem.
A crucible of informative mistakes
Kees L.
Advisor

Re: Help in Script Execution

Hello Adil,
One thing I notice:
$ FILE_LOCATION = "SMSC_TRC0:[STATS]"
$ if f$search("''f$extract(0,8,FILE_LOCATION)'[000000]stats.dir") .eqs. ""

When you extract 0,8 you get SMSC_TRC.
Shouldn't that be 0,9?

Success.
Kees.
Hein van den Heuvel
Honored Contributor

Re: Help in Script Execution

Adil,

The biggest lesson here is that DCL is NOT a self documenting language.
You need to add COMMENTS to indicated what the INTEND is for a hunk of code like the playing with the 09, 19, 29,...

Second lesson is NOT to mix variables and constants unless done consistently. An example in your code:

$ FILE_LOCATION = "SMSC_TRC0:[STATS]"
$ if f$search("''f$extract(0,8,FILE_LOCATION)'[000000]stats.dir") .eqs. ""

This gives the SUGGESTION that FILE_LOCATION is a proper variable, but then the next line uses the constant 'STATS' as hard coded.
Either go all the way, or not at all!

$dev = "SMSC_TRC0"
$dir = "STATS"
$FILE_LOCATION = dev + ":[" + dir + "]"
$if f$search( dev + ":[000000]" + dir + ".DIR",...

As Kees points out, you had a count wrong.
But best is to avoid that completely by using F$LOC to look for the ":[" or better still by using F$ELEMENT

$ ... F$ELEM(0, ":", file_location) ...

2)


Hints for the time math.
1) use formulas rather then if-then-else whenever possible such as John points out.

2) use F$CVTIME to do the minute math whenever possible as it will do the hour and day roll-overs.

3) capture a start time once, and use that, not 'now' otherwise you will by surprise at some point pick up a next minute/hour/day.

Not entirely sure what you actually want, but let's assume you want a 'next' time which should be rounded to the next 9-minute tick.

Unfortunately (for this excercise) the DATE part of an absolute time is not constant in lenght. Otherwise we could just add the minute (or a minute minus a few seconds as needed) and nuke the last digits to "9:00.00". Now we have to play. For example:

$ next_now = f$cvtime("","ABSOLUTE")
$ next_temp = f$cvtime(next_now + " + 0:1:0.0", "ABSOLUTE")
$ next_hour = f$elem(0,":",next_temp)
$ next_min = ":" + f$extract(0,1,f$eleme(1,":",next_temp)) + "9"
$ next_time = f$cvtime(next_hour + next_min, "ABSOLUTE")
$ show symb next*
NEXT_HOUR = "6-JAN-2009 15"
NEXT_MIN = ":09"
NEXT_NOW = "6-JAN-2009 15:02:48.06"
NEXT_TEMP = "6-JAN-2009 15:03:48.06"
NEXT_TIME = "6-JAN-2009 15:09:00.00"

The NEXT_NOW is optional to help show the math. Without that:

$ next_temp = f$cvtime(" + 0:1:0.0", "ABSOLUTE")
$ next_hour = f$elem(0,":",next_temp)
$ next_min = ":" + f$extract(0,1,f$eleme(1,":",next_temp)) + "9"
$ next_time = f$cvtime(next_hour + next_min, "ABSOLUTE")
$ show symb next*
NEXT_HOUR = "6-JAN-2009 15"
NEXT_MIN = ":09"
NEXT_TEMP = "6-JAN-2009 15:07:32.28"
NEXT_TIME = "6-JAN-2009 15:09:00.00"


And an example 'nuking' the last digits:

$ next_temp = f$cvtime(" + 0:1:0.0", "ABSOLUTE")
$ next_date = f$cvtime(next_temp, "ABSOLUTE", "DATE")
$ next_time = f$cvtime(next_temp, "ABSOLUTE", "TIME")
$ next_time[4,7] := 9:00.00
$ next_time = next_date + " " + next_time
$ show symb next*
NEXT_DATE = "6-JAN-2009"
NEXT_TEMP = "6-JAN-2009 15:09:15.52"
NEXT_TIME = "6-JAN-2009 15:09:00.00"


hth,
Hein.




Adil Usmani
Occasional Visitor

Re: Help in Script Execution

Thanks Team,

Please could somebody tell me the way to stop any submitted job/script in the system.
Robert Gezelter
Honored Contributor

Re: Help in Script Execution

Adil,

To delete a queued or executing batch job, the command is:

$ DELETE/ENTRY:nnn

where nnn is the queue entry number for the job (reported from the SUBMIT command and available from the SHOW QUEUE command).

A fuller description is available in the online HELP text and the OpenVMS DCL Dictionary.

- Bob Gezelter, http://www.rlgsc.com
Hein van den Heuvel
Honored Contributor

Re: Help in Script Execution

btw... if a self-submitting batch job ends up going wild (been there, done that :-), then it gets hard to catch it with DELE/ENTR.
You'll need to stop the queue, or nuke the rogue command file with for example:

$ copy nl: /over tmp.com

or

$ set file/att=(ebk:1,ffb=0) tmp.com

Hein.
Hoff
Honored Contributor

Re: Help in Script Execution

Get a job scheduling package. The classic OpenVMS use of SUBMIT is easy and familiar, but it's not comparable with the capabilities of the typical available scheduling package. (I do wish OpenVMS had job scheduling integrated.) If there's no budget for this, then take a look around for the cron and kronos packages, or such. Getting a scheduler working is a better investment of your time...