|
#1
|
|||
|
|||
SecureCRT vbs script Read files log in a lot of Unix
The vbs script reads the information in the file and logs in to Unix in bulk.
1. ip_uu_pass_path.txt four columns of information ip user password path 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 2.ssh2_auto_read-ip_user_pass.vbs ssh2_auto_read-ip_user_pass.vbs Loop read ip_uu_pass_path.txt login Unix ssh2_auto_read-ip_user_pass.vbs Script content: #$language = "VBScript" #$interface = "1.0" 'turn on synchronous mode so we don't miss any data 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 crt.screen.send chr(13) Loop 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) 'login unix crt.session.ConnectInTab "/SSH2 /L "&uname&" /PASSWORD "&pwd&" "&ip crt.screen.clear crt.Screen.Send "pwd" & chr(13) crt.Screen.Send "clear && pwd && whoami" & chr(13) End Sub |
#2
|
|||
|
|||
Hi amy_itx_aps,
What, if any, trouble are you having with the script? Is there anything I can help with?
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
vbs scripts
Yes, I have had some trouble. I want my script to switch to the corresponding directory after reading the Unix in the text one by one. My script can only log in. I can't execute some commands after logging in.
file: ip_uu_pass.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 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 |
#4
|
|||
|
|||
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 |
#5
|
|||
|
|||
Hi amy_itx_aps,
After taking a look at the script I don't see that you're capturing or using the path. I see that you're using a Split to get the IP, Username, and Password but do not capture the file path. Code:
equipmentInfo = Split(line) ip = equipmentInfo(0) uname = equipmentInfo(1) pwd = equipmentInfo(2) Code:
path = equipmentInfo(3) Code:
crt.session.ConnectInTab "/SSH2 /L "&uname&" /PASSWORD "&pwd&" "&ip crt.Screen.Send "export TMOUT=86400" & chr(13) crt.Screen.WaitForString "export TMOUT=86400"
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#6
|
|||
|
|||
vbs scripts
Yes, I need to execute some commands export TMOUT=86400 is a command I used to test to see if it can be executed. My ultimate goal is to read the value of path = equipmentInfo(3) element and execute the cd command to switch to the specified Under contents
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 equipmentInfo = Split(line) Ip = equipmentInfo(0) Uname = equipmentInfo(1) Pwd = equipmentInfo(2) ‘#add path As you said, You may be able to get the path using similar code. Path = equipmentInfo(3) ‘I started logging in and executed cd path = equipmentInfo(3) How to write? crt.session.ConnectInTab "/SSH2 /L "&uname&" /PASSWORD "&pwd&" "&ip |
#7
|
|||
|
|||
Hi amy_itx_aps,
It's still not clear to me if you need to run the CD command before or after the export command. In general, it would be sent to the remote much the same way that you're sending the export command. Code:
crt.Screen.Send "cd " & path & chr(13) Code:
crt.Screen.WaitForString("$") crt.Screen.Send "cd " & path & chr(13) issuing the next command.
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Tags |
vbs |
Thread Tools | |
Display Modes | Rate This Thread |
|
|