巡检脚本.bat
#$language = "VBScript"
#$interface = "1.0"
'XX巡检和log记录,包括GSR、7600、7500,每种类型设备生成两个文件
Sub main
crt.Screen.Synchronous = True
crt.Session.Log false
    Dim fso, f, str,path_command,logfile
    Const ForReading = 1
    Set fso = CreateObject("Scripting.FileSystemObject")
  d_date = right("00" & Month(Now()),2)&right("00" & Day(Now()),2) 
  Hours = right("00" & Hour(Time()),2)
  min = right("00" & Minute(Time()),2)
  Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists( d_date )) <> True Then
  Set f = fso.CreateFolder( d_date )
  CreateFolderDemo = f.Path
End If
If (fso.FolderExists( d_date & "\XX\")) <> True Then
  Set f = fso.CreateFolder( d_date & "\XX\")
  CreateFolderDemo = f.Path
End If
logpath = d_date & "\XX\"
logtime = Hours & min
    Set f = fso.OpenTextFile("XX巡检设备地址.txt", ForReading, 0)
    Do While f.AtEndOfStream <> True
     str = f.Readline
    If Trim(str)=";GSR" Then
      path_command = "巡检脚本\深圳GSR巡检命令.txt"
      logfile = "深圳GSR-"
    logfile =  logpath & logfile & logtime & ".log" 'GSR巡检记录成一个文件
    crt.Session.LogFileName = logfile     
      crt.Session.Log True
    end if
    If Trim(str)=";SR" Then
       crt.Session.Log false
      logfile = "XXSR-"        
    logfile =  logpath & logfile & logtime & ".log" 'GSR巡检记录成一个文件
    crt.Session.LogFileName = logfile      
       crt.Session.Log True
      path_command = "巡检脚本\深圳SR巡检命令.txt"
    end if
    If Trim(str)=";75设备" Then
       crt.Session.Log false
      logfile = "XX75-"        
    logfile =  logpath & logfile & logtime & ".log" 'GSR巡检记录成一个文件
    crt.Session.LogFileName = logfile      
       crt.Session.Log True
      path_command = "巡检脚本\XX75巡检命令.txt"
    end if   
    If Trim(str)=";access 二层65设备" Then
       crt.Session.Log false
      logfile = "XX65二层-"      
    logfile =  logpath & logfile & logtime & ".log" 'GSR巡检记录成一个文件
    crt.Session.LogFileName = logfile            
       crt.Session.Log True    
      path_command = "巡检脚本\65_二层巡检脚本.txt"
    end if
    If Trim(str)=";45" Then  
       crt.Session.Log false
      logfile = "XX45-"      
    logfile =  logpath & logfile & logtime & ".log" 'GSR巡检记录成一个文件
    crt.Session.LogFileName = logfile            
       crt.Session.Log True       
      path_command = "巡检脚本\45巡检脚本.txt"
  end if
  if  IsNumeric(left(Trim(str),2)) then
       crt.Screen.Send "telnet " & Trim(Left(Str,15)) & chr(13)
       If crt.Screen.WaitForString("sername:",10) <> True Then
         crt.Screen.Send Chr(3)
         crt.Screen.WaitForString "$"
        Else
         crt.Screen.Send "12345" & chr(13)
         crt.Screen.WaitForString "assword:"
         crt                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   .Screen.Send "12345" & chr(13)
         crt.Screen.WaitForString ">"
         Set file = fso.OpenTextFile(path_command, ForReading, 0)
          Do While file.AtEndOfStream <> True
           str = file.Readline
           crt.Screen.Send str & chr(13)         
           'if crt.Screen.Get (crt.Screen.CurrentRow,3,crt.Screen.CurrentRow,6) = "More" then
           ' crt.Screen.Send "      " & chr(13)
           'end if
           if crt.Screen.WaitForString (">",30) <> true then
            crt.Screen.Send Chr(3)
            crt.Screen.WaitForString "$"
             exit do
           else
            crt.Screen.Send chr(13)
            crt.Screen.WaitForString ">"
           end if
          Loop
         file.close()
        crt.Screen.Send "exit" & chr(13)
       End If
     End If
    crt.Screen.Send Chr(3)
    crt.Screen.WaitForString "$"
  Loop
crt.Session.Log false
f.close()
'所有设备的log信息采集
   Set f = fso.OpenTextFile("xx巡检设备地址.txt", ForReading, 0)
    Do While f.AtEndOfStream <> True
     str = f.Readline
    If Trim(str)=";GSR" Then
      logfile = "XXGSR-loginfo-"
    logfile =  logpath & logfile & logtime & ".log" 'GSR巡检记录成一个文件
    crt.Session.LogFileName = logfile     
      crt.Session.Log True
    end if
    If Trim(str)=";SR" Then
       crt.Session.Log false
      logfile = "XXSR-loginfo-"       
    logfile =  logpath & logfile & logtime & ".log" 'GSR巡检记录成一个文件
    crt.Session.LogFileName = logfile      
       crt.Session.Log True   
    end if
    If Trim(str)=";75设备" Then
       crt.Session.Log false
      logfile = "XX75-loginfo-"        
    logfile =  logpath & logfile & logtime & ".log" '75巡检记录成一个文件
    crt.Session.LogFileName = logfile      
       crt.Session.Log True
    end if    
    If Trim(str)=";access 二层65设备" Then
       crt.Session.Log false
      logfile = "XX65二层-loginfo-"      
    logfile =  logpath & logfile & logtime & ".log" '65巡检记录成一个文件
    crt.Session.LogFileName = logfile            
       crt.Session.Log True    
    end if
    If Trim(str)=";45" Then  
       crt.Session.Log false
       logfile = "XX45-loginfo-"
    logfile =  logpath & logfile & logtime & ".log" '45巡检记录成一个文件
    crt.Session.LogFileName = logfile            
       crt.Session.Log True       
  end if
  if  IsNumeric(left(Trim(str),2)) then
       crt.Screen.Send "telnet " & Trim(Left(Str,15)) & chr(13)
       If crt.Screen.WaitForString("sername:",10) <> True Then
         crt.Screen.Send Chr(3)
         crt.Screen.WaitForString "$"
        Else
         crt.Screen.Send "12345" & chr(13)
         crt.Screen.WaitForString "assword:"
         crt.Screen.Send "12345" & chr(13)
         crt.Screen.WaitForString ">"
         crt.Screen.Send "terminal length 0" & chr(13)
         crt.Screen.WaitForString ">"   
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 crt.Screen.Send "show logging | include Aug" & chr(13)
         crt.Screen.WaitForString ">"
         crt.Screen.Send "show logg buffer -100" & chr(13)
         crt.Screen.WaitForString ">"
         crt.Screen.Send "exit" & chr(13)
       End If
     End If
    crt.Screen.Send Chr(3)
    crt.Screen.WaitForString "$"
  Loop
crt.Session.Log false
f.close()
crt.Screen.Synchronous = false
End Sub


==============================================================
xx巡检设备地址.txt
;GSR                                    以下为地址
1.1.1.1                               
;SR                                      以下为地址
2.2.2.2                               65-3
;75设备
3.3.3.3                              
4.4.4.4                 
;access 二层65设备
5.5.5.5                              65-1
===============================================================
XXGSR巡检命令.txt
terminal length 0
show version
show led
show red st
show red
show gsr
sh redun states
sh diag | in SLOT | crash
sh contr fia
sh contr err
sh contr pos
show proce me | in Free|Dead
show proce cpu | exclude 0.00
show context all
sh buff | in free | hits
sh int | in line | errors
show env
show power
=================================================================