• Support
  • Articles
  • Resources
  • Products

Multiple IP connection and logging

Moderator: boris

1 postPage 1 of 1

IshmaelCallMe
Guru

Posts:
676
Joined: Thu Jan 26, 2006 2:28 am
by IshmaelCallMe » Thu Jul 16, 2009 4:39 pm
This question seems to get asked quite a bit, so I wrote a general-purpose script to connect to multiple hosts as listed in a file. Expects a tab-delimited file with the ip in the first coloumn and information in the extra coloumns available to the macro as variables line2, line3, etc. Puts log files in the TeraTERM install directory by default.

Code: Select all

  1.  
  2. ; Macro to connect to multiple ip's in tab delimited file
  3. ; and do something to each one - Ishmaelcallme 7/16/2009
  4. filename='C:\ip_file.txt'
  5. filesearch filename
  6. if result=0 then
  7.     sprintf2 stmp 'File "%s" not found' filename
  8.     messagebox stmp 'Error!'
  9.     end
  10. endif
  11. fileopen filehandle filename 0
  12. do
  13.     filereadln filehandle line
  14.     if result break
  15.     i=1     ;split line delimited by tabs into line1, line2, etc
  16.     inputstr=''
  17.     do
  18.         strlen line
  19.         if result=0 break   ;exit if nothing left in line
  20.         strscan line #9     ;look for tab
  21.         if result=0 result=999 ;if no tab, use whole rest of line
  22.         strcopy line 1 result-1 stmp
  23.         strcopy line result+1 999 line
  24.         sprintf2 var 'line%i=stmp' i
  25.         execcmnd var
  26.         sprintf '%s_%s' inputstr stmp
  27.         i=i+1
  28.     loop
  29.     strcopy inputstr 2 999 line_u   ;line_u is line separated by _ instead of tab
  30.     getdate curdate '%Y%m%d%H%M%S'
  31.     sprintf2 logfilename '%s_%s.log' line_u curdate
  32.     call startlog
  33.     sprintf2 connectstr '%s:23 /nossh' line1    ;assumes ip number is the first coloum in the ip file
  34.     ;sprintf2 connectstr '%s:22 /ssh /2' line1  ;for ssh instead of telnet
  35.     logwrite 'Attempt to connect "'
  36.     logwrite connectstr
  37.     logwrite '"'#13#10
  38.     statusbox connectstr 'Attempting to Connect to:'
  39.     connect connectstr
  40.     mpause 500
  41.     testlink
  42.     if result<>2 then
  43.         if result=0 call startlog   ;if not linked, restart TeraTERM
  44.         logwrite 'Could not connect to "'
  45.         logwrite connectstr
  46.         logwrite '"'#13#10
  47.     else
  48.    
  49.         ;*****  Insert your code here  ******
  50.         ; Remember that the tab-delimited fields in the input file are available as line1, line2, etc.
  51.    
  52.     endif
  53.     logclose
  54.     disconnect
  55.     do              ;wait for actual disconnect
  56.         mpause 10   ; Waits 10 msec.
  57.         testlink    ; Confirms the connection status.
  58.     loop while result = 2   ; Repeats if TeraTerm connects the server. See result is 2.
  59. loop
  60. testlink
  61. if result>0 closett
  62. end
  63.  
  64. :startlog
  65.     statusbox 'Startup TeraTERM and Log' 'Please wait'
  66.     mpause 500
  67.     connect '/C=257'        ;connect to invalid serial line so we can start the log
  68.     disconnect
  69.     mpause 500
  70.     logopen logfilename 1 1
  71. return
  72.  

1 postPage 1 of 1

Users browsing this forum: No registered users
cron