View Single Post
  #4  
Old 12-31-2018, 11:21 PM
amy_itx_aps amy_itx_aps is offline
Registered User
 
Join Date: Dec 2018
Posts: 8
I want a script that reads the ip user password path in the host.txt file. Use ssh2 to log in to the unix host and execute some commands on each host.

Host.txt :
192.168.80.123 oracle oracle /home/oracle/data
192.168.80.124 app app /home/app
192.168.80.3 han han /home/han

like this:
After logging in to 192.168.80.123, execute cd /home/oracle/data/
Login 192.168.80.124 After successful Execute cd /home/app
After logging in 192.168.80.3, execute cd /home/app


my vbs scripts

#$language = "VBScript"
#$interface = "1.0"

'turn on synchronous mode so we don't miss any data
crt.Screen.Synchronous = True
'crt.Screen.Synchronous = True

Sub Main

Set fso = CreateObject("Scripting.FileSystemObject")

Set file = fso.OpenTextFile("ip_uu_pass.txt")
crt.Window.Show 3

Do Until file.AtEndOfStream
line = file.ReadLine
commendAndLog line
Loop

'crt.Quit()

End Sub



Sub commendAndLog(line)
' turn off synchronous mode to restore normal input processing

crt.Screen.Synchronous = False

equipmentInfo = Split(line)
ip = equipmentInfo(0)
uname = equipmentInfo(1)
pwd = equipmentInfo(2)

Call crt.Session.Log(False)


'crt.Screen.WaitForString("$")
crt.Screen.Synchronous = True
crt.session.ConnectInTab "/SSH2 /L "&uname&" /PASSWORD "&pwd&" "&ip

crt.Screen.Send "export TMOUT=86400" & chr(13)
crt.Screen.WaitForString "export TMOUT=86400"

End Sub
Attached Images
File Type: png ssh2_auto_read-ip_user_pass.vbs_red.png (132.7 KB, 150 views)
Attached Files
File Type: txt ip_uu_pass.txt (112 Bytes, 147 views)
File Type: txt ssh2_auto_read-ip_user_pass.vbs.txt (993 Bytes, 156 views)
Reply With Quote