0

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%"xx@x.com" /sub="Your Password is ''RANDOM1' "

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

Your Password is 1218A57A
  • 1
    A typical way to wait in DCL is to use the [`WAIT`](http://h41379.www4.hpe.com/doc/83final/9996/9996pro_293.html) command. In this case, calculate the end time, e.g. _now_ + 1 minute, then use a loop to `WAIT` one second until the end time is met or exceeded. You can display the remaining time in the loop. Note that there is no guarantee that the wait period will be exact and there is also overhead in the loop, so it may not execute 60 times before running out the desired delay. – HABO Sep 22 '17 at 14:26
  • 1
    You may want to replace the last line with: ```mail a.txt smtp%"xx@x.com" /sub="Your Password is ''F$FAO("!8XL",RANDOM)' "``` and get rid of all the lines related to file I/O to finally get the wanted hex number in RANDOM1. – user2116290 Sep 23 '17 at 12:18

1 Answers1

0

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%"xx@x.com" /sub="Your Password is ''RANDOM1' "

Instead:

 $ RANDOM1 = F$FAO("!XL",RANDOM)
 $ mail a.txt smtp%"xx@x.com" /sub="Your Password is ''RANDOM1'"
Mark Diaz
  • 193
  • 1
  • 10