View Single Post
  #13  
Old 03-20-2012, 04:22 PM
_raindrop18 _raindrop18 is offline
Registered User
 
Join Date: Apr 2011
Posts: 32
thanks i have corrected based on your suggestion.
Quote:
#$language = "VBScript"
#$interface = "1.0"

Sub Main

Set g_shell = CreateObject("WScript.Shell")
nForReading = 1
strScriptPath = "C:\CRTscript"

' create an object file to be read - This is input file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDeviceFile = objFSO.GetFile(strScriptPath & "\user.txt")
Set objTS = objDeviceFile.OpenAsTextStream
strDevices = objTS.Read(objDeviceFile.Size)
' this line use to split line and the script read a text file one line at the time
vDevices = (split(strDevices, vbCrLf))
objTS.Close
strUser = "user"
' password will prompt for user input
strPasswd = crt.Dialog.Prompt("Enter password for " & strUser, "Login", "", True)
For i=0 to Ubound(vDevices)
vFields = split(vDevices(i), vbTab)
' which filed to be read
strDeviceNumber = vFields(0)
strDevice = strDeviceNumber

' Connect with the device using given user name and device name
cmd = "/SSH2 /L " & strUser & " /PASSWORD " & strPasswd & " /C 3DES /M MD5 " & strDevice
On Error Resume Next
crt.Session.Connect cmd
' Start Sync with console
crt.Screen.Synchronous = True
crt.Screen.IgnoreEscape = True

' create an object file to be read - This is input file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objstrCommand = objFSO.GetFile(strScriptPath & "\new_users.txt")
Set objTS = objstrCommand.OpenAsTextStream
strCommand = objTS.Read(objstrCommand.Size)
vCommands = (split(strCommand, vbCrLf))
Next
For Each strCommand in vCommands
If Trim(strCommands) = "" Then Exit For
Next
'1st command
crt.Screen.WaitForString "#"
'crt.Screen.Send "echo " & strCommand & " >> /disk2/fw.txt" & vbcr
crt.Screen.Send "echo " & strCommand & ">> " & "/disk2/users.txt " & vbcr
crt.Screen.WaitForString "#"
crt.Screen.WaitForString "prompt$"


' send exit command to exit from the device
crt.Screen.Send "exit" & chr(13)

' stop Syn with the secreen
crt.Screen.Synchronous = False
'Disconnect session
crt.Session.Disconnect
objTS.Close
End Sub
the problem appers to be ok now, the only issue remain..the script only read only the first line from new_user.txt file. I know I missed something but not figure out so far. I belive some where here is the error
Quote:


create an object file to be read - This is input file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objstrCommand = objFSO.GetFile(strScriptPath & "\add.txt")
Set objTS = objstrCommand.OpenAsTextStream
strCommand = objTS.Read(objstrCommand.Size)
vCommands = (split(strCommand, vbCrLf))
Next
For Each strCommand in vCommands
If Trim(strCommands) = "" Then Exit For
Next
Reply With Quote