0

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 "InReach@xxx.xxx.xxx.xxx"
$!
$  IF ANS .EQS. "2" then SSH "InReach@xxx.xxx.xxx.xxx"    
$!
$  IF ANS .EQS. "3" then SSH "InReach@xxx.xxx.xxx.xxx"
$!
$  IF ANS .EQS. "4" then SSH "InReach@xxx.xxx.xxx.xxx"
$!
$  IF ANS .EQS. "5" then SSH "InReach@xxx.xxx.xxx.xxx" 
$!
$  IF ANS .EQS. "6" then SSH "InReach@xxx.xxx.xxx.xxx"
$!
$  IF ANS .EQS. "7" then SSH "InReach@xxx.xxx.xxx.xxx"   
$!
$  IF ANS .EQS. "8" then SSH "InReach@xxx.xxx.xxx.xxx"   
$!
$  IF ANS .EQS. "9" then SSH "InReach@xxx.xxx.xxx.xxx"  
$!
$  IF ANS .EQS. "10" then SSH "InReach@xxx.xxx.xxx.xxx"   
$!                                          
$  IF ANS .EQS. "11" then SSH "InReach@xxx.xxx.xxx.xxx"
$!                                                
$  IF ANS .EQS. "12" then SSH "InReach@xxx.xxx.xxx.xxx"        
$!            
$  IF ANS .EQS. "13" then SSH "InReach@xxx.xxx.xxx.xxx"
$!             
$ GOODBYE:
$!EXIT
CW Holeman II
  • 4,661
  • 7
  • 41
  • 72
DCL Newb
  • 3
  • 2
  • There's something faintly non-technical about "dumping me out" and "be back where they started". Can you clarify things a bit? Adding `$ goto GoMenu` after the last `if` should keep you in the stored procedure (if that is your goal). An `$ on error then goto GoMenu` may help if SSH is exiting with an error when a session is terminated. [Ref](http://h41379.www4.hpe.com/doc/84final/9996/9996pro_150.html). – HABO Apr 13 '17 at 03:20
  • Thanks for the input - so, by "dumping me out" I mean I was returned to a VMS prompt versus going back to the menu. The goal would be, after the user ends the remote session, they be returned to the menu. – DCL Newb Apr 13 '17 at 17:10
  • Also, how do I keep it from exiting if they choose a choice that is not listed? If the user types W, for example, it just exits the program and returns the user to a VMS prompt. – DCL Newb Apr 13 '17 at 17:22
  • BTW - I really appreciate the help! – DCL Newb Apr 13 '17 at 17:23

2 Answers2

2
  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
Hein
  • 1,453
  • 8
  • 8
  • 6. Don't create global symbols for local use. 7. Do use error handling code to handle errors rather than just consuming them without inspection. – HABO Apr 14 '17 at 03:16
  • HEIN - tested and working well. I added two lines to this code, taking from HABO's example. When I tested, after exiting the connection to the MRV, I was returned to the DCL prompt. I added: 'on error then goto MENU' and 'goto menu' at the bottom. – DCL Newb Apr 18 '17 at 14:12
0

This may be more to your liking:

$ ! MRV Terminal Server Connection Menu
$ !       
$ CLS :== SET TERMINAL/WIDTH=80
$ WT :== WRITE SYS$OUTPUT
$ !
$ 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
$ !
$ 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 Houseclean
$ else if Ans .eqs. "1"
$   then
$   SSH "InReach@xxx.xxx.xxx.xxx"
$ else if Ans .eqs. "2"
$   then
$   SSH "InReach@xxx.xxx.xxx.xxx"
$ else if Ans .eqs. "3"
$   then
$   SSH "InReach@xxx.xxx.xxx.xxx"
$ else if Ans .eqs. "4"
$   then
$   SSH "InReach@xxx.xxx.xxx.xxx"
$ else if Ans .eqs. "5"
$   then
$   SSH "InReach@xxx.xxx.xxx.xxx"
$ else if Ans .eqs. "6"
$   then
$   SSH "InReach@xxx.xxx.xxx.xxx"
$ else if Ans .eqs. "7"
$   then
$   SSH "InReach@xxx.xxx.xxx.xxx"
$ else if Ans .eqs. "8"
$   then
$   SSH "InReach@xxx.xxx.xxx.xxx"
$ else if Ans .eqs. "9"
$   then
$   SSH "InReach@xxx.xxx.xxx.xxx"
$ else if Ans .eqs. "10"
$   then
$   SSH "InReach@xxx.xxx.xxx.xxx"
$ else if Ans .eqs. "11"
$   then
$   SSH "InReach@xxx.xxx.xxx.xxx"
$ else if Ans .eqs. "12"
$   then
$   SSH "InReach@xxx.xxx.xxx.xxx"
$ else if Ans .eqs. "13"
$   then
$   SSH "InReach@xxx.xxx.xxx.xxx"
$ else
$   ! Handle any unexpected input.
$   WT "Beg your pardon?" ! Immediately followed by clearing the screen.  Sigh.
$   endif
$ !
$ ! We did what they wanted.  How else may we serve?
$ goto Menu
$ !             
$ Houseclean:
$   ! Nothing else to do.
$   exit ! Or perhaps you prefer $ logout
HABO
  • 15,314
  • 5
  • 39
  • 57