VanDyke Software

Tips

Index

Logon Script to Log On to Multiple Hosts with SecureCRT®

A developer at a telecommunications firm submitted this scripting tip, which logs on to multiple hosts using a common password. The script also allows him to easily change passwords on the dozens of sessions he has to manage. This script can be used with SecureCRT for Windows.

"Corporate security requires passwords to change every month. I use a single VBScript logon script for all these sessions and then I only change one script every time I have to change the common password. I even have the script customize itself, depending on which host is using it, once the logon sequence is done."

The script below logs on with the information that is common to all the servers. The script then reads the screen to get the name of the machine to which it's connected. That machine name is then used to decide on additional setup that can be automated before the script terminates and the Telnet session goes interactive.

Keep in mind that if the password is stored in a script, it will be in plain text.

Here is a link to VBScript logon script: MultiSessionLogin_vbs.txt

To learn more about scripting for SecureCRT, visit our Scripting Examples web page, or the online Scripting Essentials guide.

'~~~~~~~~~~~~~~~~~~~~ Begin MultiSessionLogin.vbs ~~~~~~~~~~~~~~~~~~~~~~~~~~

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

' script for logging on to multiple servers

Sub Main()
    ' turn on synchronous mode
    crt.Screen.Synchronous = True

    ' login name
    crt.Screen.WaitForString "ogin:"
    crt.Screen.Send "userid" & VbCr

    ' password
    crt.Screen.WaitForString "assword:"
    crt.Screen.Send "passwd" & VbCr

    ' find machine name
    crt.Screen.WaitForString "$ "
    crt.Screen.Send "uname -n" & VbCr
    crt.Screen.WaitForString "$ "
    row = crt.Screen.CurrentRow - 1
    mach = Trim(crt.Screen.Get(row, 1, row, 20))

    ' decide if more commands are needed
    Select Case mach
        Case "bldsrv9"
            crt.Screen.Send "cd blddir" & VbCr
            crt.Screen.WaitForString "$ "
            crt.Screen.Send ". ./.bldprof9" & VbCr
            crt.Screen.WaitForString "$ "
            crt.Screen.Send "cd $MYNODE" & VbCr

        Case "bldsrv10", "bldsrv11"
            crt.Screen.Send "cd blddir" & VbCr
            crt.Screen.WaitForString "$ "
            crt.Screen.Send ". ./.bldprof10" & VbCr
            crt.Screen.WaitForString "$ "
            crt.Screen.Send "cd $MYNODE" & VbCr
    End Select

    ' setup the test servers (names start with tstsrv)
    If Left(mach, 6) = "tstsrv" Then
        crt.Screen.Send ". ./.tstprofile" & VbCr
        crt.Screen.WaitForString "$ "
    End If

    ' turn off synchronous mode
    crt.Screen.Synchronous = False
End Sub

'~~~~~~~~~~~~~~~~~~~~ MultiSessionLogin.vbs ~~~~~~~~~~~~~~~~~~~~~~~~~~

VanDyke Software uses cookies to give you the best online experience. Before continuing to use this site, please confirm that you agree to our use of cookies. Please see our Cookie Usage for details.