Automation

last person joined: 2 days ago 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  Best way to ssh into multiple SRX and run unqiue set commands

    Posted 01-21-2017 18:26

    I need to change the local identity on 200 SRX. Each SRX will have a unique local idenity. I've never automated any tasks before. Whats the best way to do this?



  • 2.  RE: Best way to ssh into multiple SRX and run unqiue set commands

     
    Posted 01-21-2017 23:02

    Hi Folks,

    I do this often with expect script from a external unix/linux box

     

    #!/usr/bin/expect
    set timeout 10
    set name [lindex $argv 0]
    set port [lindex $argv 1]
    spawn telnet -l lab $name $port
    expect "Password:"
    send "<type password>\n"
    expect "> "
    send "edit\n"
    expect "# "
    send "<commands to configure>\n"
    expect "# "
    send "<commands to configure>\n"
    expect "# commit and-quit "
    expect "> "
    send "exit\n"

     

     



  • 3.  RE: Best way to ssh into multiple SRX and run unqiue set commands

    Posted 01-22-2017 01:47

    thanks for the reply Python. I've been reading quite a bit about using Expect for automation. The learning curve is for me is huge since im new to programming and linux. Are they're any windows based solutions?



  • 4.  RE: Best way to ssh into multiple SRX and run unqiue set commands

    Posted 01-22-2017 03:13

    Hello there,


    @Gunner909 wrote:

     Are they're any windows based solutions?


    SecureCRT supports VB scripts.

    Example below for telnetting into several boxes & collecting their configs using VBscript.

    Boxes' hostnames are supplied from text file.

    # $language = "VBScript"
    # $interface = "1.0"
    
    Const username = "aarseniev"             ' Username to use for login
    Const password = "password123"        ' Password for corresponding user
    
    
    Sub Main
    
    Dim objFso, objShell, objTextStream, szLine
    Dim vSessionsArray()
    Dim nSessionCount
    nSessionCount = 0
    
    ' Start of with a reasonable size for the array
    ReDim vSessionsArray(300)
    
    ' Read in Sessions from a file that contains session names (one per line)
    Set objFso = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("WScript.Shell")
    Dim szMyDocs
    ' edit the following paths accordingly
    ' rootdir may be a place where you store all your lists (e.g. routers-site1, routers-site2 etc.)
    rootdir = objShell.SpecialFolders("C:")
    Set objTextStream = objFso.OpenTextFile(rootdir & "\MyDocuments\RouterList.txt", 1, false)
    
    Dim host
    Do While Not objTextStream.AtEndOfStream
    host = Trim(objTextStream.ReadLine)
    ' Don't add empty lines/sessions
    if host <> "" then
    vSessionsArray(nSessionCount) = host
    nSessionCount = nSessionCount + 1
    end if
    Loop
    
        crt.Screen.Synchronous = True
        crt.Screen.Send "date" & vbCr
        crt.Screen.WaitForString "$ " 
    
                                      csuffix = "-config-csco"
                                      jsuffix = "-config-jnpr"
                                      
                                      
                                      For Each host in vSessionsArray
           
      crt.Screen.Send "telnet " & host & vbCr
        result = crt.screen.WaitForStrings("Username:", "login:", "Resolver Error")
         ' 1 for cisco, 2 for juniper, 3 for no-such-name
      If result = 1 Then
        crt.Screen.Send username & vbCr
        crt.Screen.WaitForString "Password: "
        crt.Screen.Send password & vbCr
        crt.Screen.WaitForString "#"
        call EnableCommandIOS ("term len 0", host)
        crt.Screen.Send "exit" & vbCr
        crt.Screen.WaitForString "$ "
      End if
      If result = 2 Then
        crt.Screen.Send username & vbCr
        crt.Screen.WaitForString "Password:"
        crt.Screen.Send password & vbCr
        crt.Screen.WaitForString ">"
        call CommandJunos ("set cli screen-length 0", host)
        crt.Session.LogFileName = "c:\MyDocuments\ScriptOutput\" & host & jsuffix
        crt.Session.Log(TRUE)
    
                            call CommandJunos ("show configuration", host)
        crt.Session.Log(FALSE)
        crt.Screen.Send "exit" & vbCr
        crt.Screen.WaitForString "$ "  
      End if
      If result = 3 then
      End if
      
       Next
    
        crt.Screen.Synchronous = False
    End Sub
    
    
    

    HTH

    Thx

    Alex



  • 5.  RE: Best way to ssh into multiple SRX and run unqiue set commands
    Best Answer

     
    Posted 01-22-2017 09:12

    Hi Folks,

    If you are not used to scripts; the straightforward easy way to do the same with secureCRT,

     

    Using The Chat Window To Send Commands To Multiple SecureCRT® Sessions

     

    Broadcast Commands Using Chat

    Broadcasting commands uses the SecureCRT chat window, which appears underneath the session window. Chat allows you to type in commands that are only sent to the remote when you press the ENTER key (when not in the chat window, each character is sent to the remote as soon as you type it). You can prepare multiple lines of commands in the chat window by using the CTRL+ENTER key combination.

    To open the chat window, select Chat window on the View menu. Once all your sessions are started as tabs, right-click in the chat window and choose Send Chat to All Sessions. With this option enabled, each command entered into the chat window is sent to every tab in the SecureCRT window.

     



  • 6.  RE: Best way to ssh into multiple SRX and run unqiue set commands

    Posted 01-22-2017 19:05

    Thanks for the info. I appreaciate it. I'm sure you'll guys will notice me as a regular in this forum. The # of devices is growing but the # of support staff isn't. Automation is very much going to be a priority of mine.



  • 7.  RE: Best way to ssh into multiple SRX and run unqiue set commands

     
    Posted 01-22-2017 19:16

    Hi Folks,

    We are always there to help you with any questions you might have.I love to automate anything I can that involves repeating tasks.