Advertisement

08.27.2008 at 09:43AM PDT, ID: 23682644
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Help with VB Script for SecureCRT

Asked by darkoth in VB Script

Tags:

I'm using the following script to run in SecureCRT. It's basically a script to go out and change all the root passwords on our servers.

The problem I'm having is that when it does a cat server_list.txt and stores it into the array, I want to remove the last line from my file:

For example, right now I do this:
]# cat server_list.txt
frodo
samwise
#$

It reads them in and then ssh's to each server, executes the command and continues. However when it reaches the end it tries to ssh #$ or even ssh to nothing...  basically the output below

]# ssh
Usage: ssh [options] host [command]
Options:
  -l user     Log in using this user name.
  -n          Redirect input from /dev/null.
  -F config   Config file (default: ~/.ssh/config).
  -A          Enable authentication agent forwarding.
  -a          Disable authentication agent forwarding (default).
  -X          Enable X11 connection forwarding.
  -x          Disable X11 connection forwarding (default).
  -i file     Identity for public key authentication (default: ~/.ssh/identity)
  -t          Tty; allocate a tty even if command is given.
  -T          Do not allocate a tty.
  -v          Verbose; display verbose debugging messages.
              Multiple -v increases verbosity.
  -V          Display version number only.
  -q          Quiet; don't display any warning messages.
  -f          Fork into background after authentication.
  -e char     Set escape character; ``none'' = disable (default: ~).
  -c cipher   Select encryption algorithm
  -m macs     Specify MAC algorithms for protocol version 2.
  -p port     Connect to this port.  Server must be on the same port.
  -L listen-port:host:port   Forward local port to remote address
  -R listen-port:host:port   Forward remote port to local address
              These cause ssh to listen for connections on a port, and
              forward them to the other side by connecting to host:port.
  -D port     Enable dynamic application-level port forwarding.
  -C          Enable compression.
  -N          Do not execute a shell or command.
  -g          Allow remote hosts to connect to forwarded ports.
  -1          Force protocol version 1.
  -2          Force protocol version 2.
  -4          Use IPv4 only.
  -6          Use IPv6 only.
  -o 'option' Process the option as if it was read from a configuration file.
  -s          Invoke command (mandatory) as SSH2 subsystem.
  -b addr     Local IP address.

Looking for help on how to resolve this. It does everything else the right way and only errors at the end which is fine, but I would rather have it send me my msgbox saying its done :). Thanks.

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
#$language = "VBScript"
#$interface = "1.0"
 
Sub Main
	Dim szPrompt, objTab, szHost, vServerList
 
	szPrompt = "#$"
	Set objTab = crt.GetScriptTab
	objTab.Screen.Synchronous = True
	objTab.Screen.IgnoreEscape = True
 
	Do
		szPassword = crt.dialog.prompt("Please enter your password: ", "Password: ", "", True)
		If szPassword = "" then exit sub
 
		szRootPassword = crt.dialog.Prompt("Please enter the current ROOT password: ", "Root Password", "", True)
		If szRootPassword = "" then exit sub
 
		szNewPassword = crt.dialog.prompt("Please enter the new ROOT password: ", "New Password", "", True)
		If szNewPassword = "" then exit sub
                
		szConfirmPassword = crt.dialog.prompt("Please confirm the new ROOT password: ", "Confirm Password", "", True)
		If szConfirmPassword = "" then exit sub
                
		if szNewPassword <> szConfirmPassword then
			MsgBox "User did not provide matching passwords"
		Else
			Exit Do
		End if
	Loop
 
	szCommand = "cat server_list.txt"
        objTab.Screen.Send szCommand & vbcr
 
	objTab.Screen.WaitForString szCommand & vbcr
        vServerList = Split(objTab.Screen.ReadString(szPrompt), vbcr)
 
        For Each szHost in vServerList
		' Get rid of any carriage returns or line feeds that still may be
		' remaining in szHost
		szHost = Replace(szHost, "#$", "")
		szHost = Replace(Replace(szHost, vblf, ""), vbcr, "")
	    
		objTab.Screen.Send "ssh " & szHost & vbcr
		Do
			Dim szResult
			szResult = Crt.Screen.WaitforStrings("Are you sure you want to continue connecting (yes/no)? ", "Password:", 60)
			If szResult = 1 Then
				objTab.Screen.Send "yes" & vbcr
				objTab.Screen.WaitforString "Password: "
				objTab.Screen.Send szPassword & vbcr
				exit do
			End If
			If szResult = 2 Then
                       		objTab.Screen.Send szPassword & vbcr
                        	exit do
                	End If 
			If szResult = 0 Then
				MsgBox "We timed out"
				Exit sub
			End if
		Loop
		objTab.Screen.WaitforString "TERM = (xterm) " 
		objTab.Screen.Send "vt100" & vbcr
		objTab.Screen.WaitforString " ]# "
		objTab.Screen.Send "su -" & vbcr
		objTab.Screen.WaitForString "Password:"
		objTab.Screen.Send szRootPassword & vbcr
		objTab.Screen.WaitforString "TERM = (xterm) " 
		objTab.Screen.Send "vt100" & vbcr
		objTab.Screen.WaitforString " ]# "
		objTab.Screen.Send "passwd root" & vbcr
		ObjTab.Screen.WaitForString "New Password: "
		objTab.screen.Send szNewPassword & vbcr
		objTab.Screen.WaitForString "Re-enter new Password:"
		objTab.Screen.Send szNewPassword & vbcr
		objTab.Screen.WaitForString "passwd: password successfully changed for root"
		objTab.Screen.Send "exit" & vbcr
		objTab.screen.WaitForString "]#"
		objTab.Screen.Send "exit" & vbcr
		objTab.screen.WaitForString "]#"
	Next
	MsgBox "Script Completed."
End Sub
[+][-]08.27.2008 at 02:31PM PDT, ID: 22329411

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: VB Script
Tags: VBS
Sign Up Now!
Solution Provided By: RobSampson
Participating Experts: 1
Solution Grade: A
 
 
[+][-]08.28.2008 at 05:33AM PDT, ID: 22334014

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.28.2008 at 05:43AM PDT, ID: 22334077

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.28.2008 at 06:18AM PDT, ID: 22334401

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.28.2008 at 06:27AM PDT, ID: 22334477

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.28.2008 at 06:37AM PDT, ID: 22334583

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.31.2008 at 11:42PM PDT, ID: 22357882

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628