Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 12-30-2018, 11:26 PM
amy_itx_aps amy_itx_aps is offline
Registered User
 
Join Date: Dec 2018
Posts: 8
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
Reply With Quote
  #2  
Old 12-31-2018, 09:33 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
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
Reply With Quote
  #3  
Old 12-31-2018, 09:01 PM
amy_itx_aps amy_itx_aps is offline
Registered User
 
Join Date: Dec 2018
Posts: 8
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
Reply With Quote
  #4  
Old 12-31-2018, 10: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, 1046 views)
Attached Files
File Type: txt ip_uu_pass.txt (112 Bytes, 963 views)
File Type: txt ssh2_auto_read-ip_user_pass.vbs.txt (993 Bytes, 985 views)
Reply With Quote
  #5  
Old 01-03-2019, 08:47 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
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)
You may be able to get the path using similar code.

Code:
path = equipmentInfo(3)
Towards the end of the script I see that you're connecting using ConnectInTab but the only other thing sent is an export TMOUT.

Code:
crt.session.ConnectInTab "/SSH2 /L "&uname&" /PASSWORD "&pwd&" "&ip

crt.Screen.Send "export TMOUT=86400" & chr(13)
crt.Screen.WaitForString "export TMOUT=86400"
Did you want to change directories before or after sending the TMOUT?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #6  
Old 01-06-2019, 07:15 AM
amy_itx_aps amy_itx_aps is offline
Registered User
 
Join Date: Dec 2018
Posts: 8
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
Reply With Quote
  #7  
Old 01-06-2019, 09:52 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
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)
You will typically want to wait for an indication that the remote system is ready to accept the command. This can be done by waiting for the prompt. Borrowing from your code, it may look something like:

Code:
crt.Screen.WaitForString("$")
crt.Screen.Send "cd " & path & chr(13)
You would then want to wait for an indication the command finished and the remote is ready for the next command before
issuing the next command.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply

Tags
vbs

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 02:12 AM.