Search code examples
openvmsdcl

DCL Programming - Remote connections


First, I am a total newb, and shouldn't be allowed around a keyboard. That said, I am trying to write a DCL .COM file that will allow a user to connect to a remote device by selecting it from a list.

All I want to do is allow them to pick a device and connect, and then when they disconnect from the device, be back where they started. It keeps dumping me out after I terminate the remote connection.

The operating system is OpenVMS. Here is the code (where xxx.xxx.xxx.xxx will be an IP address of the remote system).

Any help will be greatly appreciated!

$!      MRV Terminal Server Connection Menu
$!       
$ ON ERROR THEN $ LOGOUT
$ GOMENU:
$!
$ CLS:==SET TERM/WIDTH=80
$ WT:==WRITE SYS$OUTPUT
$!
$ CLS
$ WT "   MRV Terminal Server Connection Menu "
$ WT " "
$ WT "  1     MRV 1"
$ WT "  2     MRV 2"
$ WT "  3     MRV 3"
$ WT "  4     MRV 4" 
$ WT "  5     MRV 5"
$ WT "  6     MRV 6"
$ WT "  7     MRV 7"
$ WT "  8     MRV 8"
$ WT "  9     MRV 9"
$ WT "  10     MRV 10"
$ WT "  11     MRV 11"
$ WT "  12     MRV 12"
$ WT "  13     MRV 13"
$ WT "  14     MRV 14"  
$ WT " "
$ WT " "
$ WT " "
$ WT " "
$ WT " "                                    
$ WT "  X     EXIT"
$ WT " "
$ INQUIRE ANS "Select the MRV you wish to connect to:"
$!
$!
$  IF ANS .EQS. "X" then goto goodbye
$!                                          
$!
$  IF ANS .EQS. "1" then SSH "[email protected]"
$!
$  IF ANS .EQS. "2" then SSH "[email protected]"    
$!
$  IF ANS .EQS. "3" then SSH "[email protected]"
$!
$  IF ANS .EQS. "4" then SSH "[email protected]"
$!
$  IF ANS .EQS. "5" then SSH "[email protected]" 
$!
$  IF ANS .EQS. "6" then SSH "[email protected]"
$!
$  IF ANS .EQS. "7" then SSH "[email protected]"   
$!
$  IF ANS .EQS. "8" then SSH "[email protected]"   
$!
$  IF ANS .EQS. "9" then SSH "[email protected]"  
$!
$  IF ANS .EQS. "10" then SSH "[email protected]"   
$!                                          
$  IF ANS .EQS. "11" then SSH "[email protected]"
$!                                                
$  IF ANS .EQS. "12" then SSH "[email protected]"        
$!            
$  IF ANS .EQS. "13" then SSH "[email protected]"
$!             
$ GOODBYE:
$!EXIT

Solution

    1. Don't muck with terminal settings!
    2. INQUIRE is bad, more often than not, but good enough for now.
    3. Use TYPE for large chunks of constant text
    4. Table lookup, or associative arrays are so much cleaner than long IF THEN ELSES
    5. Use F$TYPE to see if a symbol is a STRING or INTEGER or NOTHING-AT-ALL

    Check this out for some ideas:

    $ ! MRV Terminal Server Connection Menu
    $ !
    $ CLS :== TYPE/PAGE NL: !  Please don't muck with my screen setting as in: SET TERMINAL/WIDTH=80
    $ WT :== WRITE SYS$OUTPUT
    $ ANS_1  =  "aap.xxx.xxx.xxx"
    $ ANS_2  = "noot.xxx.xxx.xxx"
    $ ANS_14 = "mies.xxx.xxx.xxx"
    $ !
    $ Menu:
    $ !
    $ ! If SSH (or anything else) causes an error, go back to the menu.
    $ !   It is placed here because it needs to be set again after each error.
    $ on error then $ goto Menu
    $ !
    $ type/page sys$input:
    
       MRV Terminal Server Connection Men
    
      1     MRV 1
      2     MRV 2
      :
      14    MRV 14
    
      X     EXIT"
    $ !
    $ INQUIRE ANS "Select the MRV you wish to connect to:"
    $ !
    $ if ANS .eqs. "X" then exit
    $ if f$type(ANS_'ANS') .eqs. ""
    $ then
    $   ! Handle any unexpected input.
    $   WT "Beg your pardon? ''ANS' ? " ! Immediately followed by clearing the screen.  Sigh.
    $   WAIT 0:0:3
    $ !
    $ ! We did what they wanted.  How else may we serve?
    $   goto Menu
    $ endif
    $  command = "SSH """ +  ANS_'ANS + """"
    $ write sys$output "Going to execute : " + command
    $
    $!  'command      ! Remove Comment for real action