0

首先,我是一个完全的新手,不应该被允许在键盘周围。也就是说,我正在尝试编写一个 DCL .COM 文件,该文件将允许用户通过从列表中选择它来连接到远程设备。

我要做的就是让他们选择一个设备并连接,然后当他们与设备断开连接时,回到他们开始的地方。在我终止远程连接后,它一直把我甩出去。

操作系统是 OpenVMS。这是代码(其中 xxx.xxx.xxx.xxx 将是远程系统的 IP 地址)。

任何帮助将不胜感激!

$!      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
4

2 回答 2

2
  1. 不要乱用终端设置!
  2. INQUIRE 很糟糕,通常情况下,但现在已经足够了。
  3. 对大块常量文本使用 TYPE
  4. 表查找或关联数组比 long IF THEN ELSES 干净得多
  5. 使用 F$TYPE 查看符号是 STRING 还是 INTEGER 或 NOTHING-AT-ALL

看看这个以获得一些想法:

$ ! 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
于 2017-04-14T02:36:35.720 回答
0

这可能更符合您的喜好:

$ ! 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
于 2017-04-13T20:39:50.243 回答