How to create a countdown timer in DCL - OpenVMS

288 views Asked by At

I wrote a script which will send an OTP (One Time Password) to users Mail ID. So whenever System sends the OTP to the user, I want to start a countdown timer of 1 Minute. But am not sure how to start the Countdown timer using DCL Scripting..Any Idea ?

Below is the script which I am using to generate the OTP..But I need to have a countdown Timer...Is it possible to display the countdown on screen ? Please Help !!

$! RAND - returns a positive random number ("RANDOM") between 0 and 
$!        __CEIL - 1. 
$! sharris-at-sdsdmvax.fb3.noaa.gov 
$ RAND: 
$ 
$ IF F$TYPE(__SEED) .EQS. "" 
$ THEN 
$     ! seed the random number generator, ... 
$     __NOW = F$CVTIME() 
$     __HOUR = 'F$EXTRACT(11,2,__NOW)' 
$     __MINUTE = 'F$EXTRACT(14,2,__NOW)' 
$     __SECOND = 'F$EXTRACT(17,2,__NOW)' 
$     __TICK = 'F$EXTRACT(20,2,__NOW)' 
$ 
$     __SEED == __TICK + (100 * __SECOND) + (6000 * __MINUTE) + - 
         (360000 * __HOUR) 
$     ! the generator tends to do better with a large, odd seed, ... 
$     __SEED == (__SEED .OR. 1) 
$     ! clean up, ... 
$     DELETEX/SYMBOL __NOW 
$     DELETEX/SYMBOL __HOUR 
$     DELETEX/SYMBOL __MINUTE 
$     DELETEX/SYMBOL __SECOND 
$     DELETEX/SYMBOL __TICK 
$ ENDIF 
$ 
$ IF F$TYPE(__CEIL) .EQS. "" THEN __CEIL = %X3FFFFFFF 
$ 
$ __SEED == __SEED * 69069 + 1 
$ RANDOM == (__SEED.AND.%X3FFFFFFF)/(%X40000000/__CEIL) 
$ define sys$output MANAGERS:[EMAL]random.txt
$ sh sym RANDOM
$ deassign sys$output
$ sear MANAGERS:[EMAL]random.txt random /out=MANAGERS:[EMAL]random1.txt
$ open in MANAGERS:[EMAL]random1.txt
$ LOOP4:
$ READ/END_OF_FILE=ENDIT4 IN RANDO
$ GOTO LOOP4
$ ENDIT4:
$ close in
$ RANDOM1 = F$EXTRACT(30,8,RANDO)
$ sh sym RANDOM1
$ mail a.txt smtp%"[email protected]" /sub="Your Password is ''RANDOM1' "

when I run the above script, my OTP will be as follows:

Your Password is 1218A57A
1

There are 1 answers

0
Mark Diaz On

Here's a basic DCL loop that displays a countdown. As others said, it will not be exactly 60 seconds, but I'm guessing that is not important.

 $       X = 60
 $ 1$:   WRITE SYS$OUTPUT X, " Seconds"
 $       WAIT 00:00:01.00
 $       X = X - 1
 $       IF X .GT. 0 THEN GOTO 1$
 $

In case it was not clear from the other comment, unless you are saving the password in the random.txt file for some reason, you can simplify the last bit of your script. Rather than:

 $ define sys$output MANAGERS:[EMAL]random.txt
 $ sh sym RANDOM
 $ deassign sys$output
 $ sear MANAGERS:[EMAL]random.txt random /out=MANAGERS:[EMAL]random1.txt
 $ open in MANAGERS:[EMAL]random1.txt
 $ LOOP4:
 $ READ/END_OF_FILE=ENDIT4 IN RANDO
 $ GOTO LOOP4
 $ ENDIT4:
 $ close in
 $ RANDOM1 = F$EXTRACT(30,8,RANDO)
 $ sh sym RANDOM1
 $ mail a.txt smtp%"[email protected]" /sub="Your Password is ''RANDOM1' "

Instead:

 $ RANDOM1 = F$FAO("!XL",RANDOM)
 $ mail a.txt smtp%"[email protected]" /sub="Your Password is ''RANDOM1'"