Jump to content

Recommended Posts

Posted

I'm trying to write a script to automate an annoying bit of reporting I have to do multiple times a day in my work.

So far the script logs into putty connects to the which ever bit of equipment I want to investigate copies 'all to clipboard', pates into a new notepad file and deletes the first 20 or so lines leaving me with just the bit i'm interested in .

basically I want to get

Sync=locked, DAC=2021, status=no alarm/no warning.
(where DAC is the decimal of the last 3 HEX characters of the DAC value line and locked or unlocked has to be reported and status has to show what if any alarms are reported in the 'sta' box)

from

+-----------------------------------+
 |        SYN Information         |
 +----------------------+------------+
 |  Algo version        |    10  |
 |  Interface version   |     1  |
 |  Debug mode        |  OFF    |
 |  DAC value          |   0x07DC   |
 |  Clock source        |   E1/T1/0  |
 |  Holdover mode      |     OFF    |
 |  Activity board    |  ON  |
 |  Synchro          |  Unlocked  |
 |  Status            | 0x00000000 |
 +----------------------+------------+
/pltf/syn> sta
 +--------------------------+
 |  SYN Status 0x00000000   |
 +--------------------------+
 |  No alarm / No warning   |
 +--------------------------+
/pltf/syn>

and sometimes the second might be like

/pltf/syn> sta
 +--------------------------+
 |  SYN Status 0x00020008   |
 +--------------------------+
 |   WOCVCXOReachMTP1      |
 |   Some other alarms    |
 +--------------------------+
/pltf/syn>

if there are multiple alarm codes they each show on a new line

the DAC value should be easy enough just x downs and x rights then select three characters.(and then copy/paste in into calc and convert from hex to dec and copy paste back)

but how do i say clip for everything between

+--------------------------+
 |  SYN Status 0x00020008   |
 +--------------------------+
and
+--------------------------+

secondly How do I store this information as variables in the script and not just in the windows pasteboard, would this be clipget and clipput. For instance I want send the results out of calc to a variable instead of keeping them in the pasteboard.

So can anyone please help me to figure out what the best approach for this is?

Posted (edited)

oh and here is the script so far (striped of logins etc)

AutoItSetOption ("MouseCoordMode", 0)
Dim $ip1
$ip1 = InputBox("SITE IP", "Enter Site IP", "xxx.xxx", "", "190","115")



func putty()
    RUN('"C:\Program Files\PuTTY\putty.exe" -load "main server"')
    WinActivate("xx.xx.xx.xx - PuTTY")
    WinWaitActive("xx.xx.xx.xx - PuTTY")
    sleep(1000)
    Send("user")
    Send("{ENTER}")
    Sleep(300)
    Send("pass")
    Send("{ENTER}")
    Sleep(300)
    Send("bash")
    Send("{ENTER}")
    Sleep(300)
    Send("telnet "& $ip1 & " xxport")
    Send("{ENTER}") 
    Sleep(300)
    send("user")
    Send("{ENTER}")
    sleep(300)
    send("pass")
    Send("{ENTER}")
    sleep(300)
    Send("pltf")
    Send("{ENTER}")
    sleep(300)
    Send("syn")
    Send("{ENTER}")
    sleep(300)
    Send("info")
    Send("{ENTER}")
    sleep(300)
    Send("sta")
    Send("{ENTER}")
    sleep(300)
    MouseClick("Right", 5, 5, 1)
    Sleep(100)
    Send("+{down 13}")
    Send("{ENTER}")
    Sleep(100)
    Send("exit")
    Send("{ENTER}")
    Sleep(100)
    Send("exit")
    Send("{ENTER}")
    Sleep(100)
    Send("exit")
    Send("{ENTER}")
    Sleep(100)
    
EndFunc

func notepad()
    run("notepad.exe")
    WinWaitActive("Untitled - Notepad")
    Sleep(100)
    Send("^V")
    send("^{HOME}")
    send("+{down 27}")
    send("{bs}")
    
EndFunc

putty()
notepad()
Exit
Edited by Skins
Posted

Dim $sText1 = '+-----------------------------------+' & @CRLF & _
             '|          SYN Information          |' & @CRLF & _
             '+----------------------+------------+' & @CRLF & _
             '|  Algo version        |     10     |' & @CRLF & _
             '|  Interface version   |      1     |' & @CRLF & _
             '|  Debug mode          |     OFF    |' & @CRLF & _
             '|  DAC value           |   0x07DC   |' & @CRLF & _
             '|  Clock source        |   E1/T1/0  |' & @CRLF & _
             '|  Holdover mode       |     OFF    |' & @CRLF & _
             '|  Activity board      |     ON     |' & @CRLF & _
             '|  Synchro             |  Unlocked  |' & @CRLF & _
             '|  Status              | 0x00000000 |' & @CRLF & _
             '+----------------------+------------+' & @CRLF & _
             '/pltf/syn> sta' & @CRLF & _
             '+--------------------------+' & @CRLF & _
             '|  SYN Status 0x00020008   |' & @CRLF & _
             '+--------------------------+' & @CRLF & _
             '|   WOCVCXOReachMTP1       |' & @CRLF & _
             '|   Some other alarms      |' & @CRLF & _
             '|   s o m e o_TheR         |' & @CRLF & _
             '+--------------------------+' & @CRLF & _
             '/pltf/syn>'
             
Dim $sText2 = '+-----------------------------------+' & @CRLF & _
             '|          SYN Information          |' & @CRLF & _
             '+----------------------+------------+' & @CRLF & _
             '|  Algo version        |     10     |' & @CRLF & _
             '|  Interface version   |      1     |' & @CRLF & _
             '|  Debug mode          |     OFF    |' & @CRLF & _
             '|  DAC value           |   0x07DC   |' & @CRLF & _
             '|  Clock source        |   E1/T1/0  |' & @CRLF & _
             '|  Holdover mode       |     OFF    |' & @CRLF & _
             '|  Activity board      |     ON     |' & @CRLF & _
             '|  Synchro             |  Unlocked  |' & @CRLF & _
             '|  Status              | 0x00000000 |' & @CRLF & _
             '+----------------------+------------+' & @CRLF & _
             '/pltf/syn> sta' & @CRLF & _
             '+--------------------------+' & @CRLF & _
             '|  SYN Status 0x00020008   |' & @CRLF & _
             '+--------------------------+' & @CRLF & _
             '|  No alarms / No warning  |' & @CRLF & _
             '+--------------------------+' & @CRLF & _
             '/pltf/syn>'
             
             
Dim $sMsg = _SyncStatus($sText1)
MsgBox(0x30, 'Title', $sMsg)

$sMsg = _SyncStatus($sText2)
MsgBox(0x20, 'Title', $sMsg)



Func _SyncStatus($sStr)
    
    Local $aDAC, $DAC = 'DAC='
    Local $sStatus = 'Status=', $sSync = 'Sync='
    
    If StringRegExp($sStr, '(?i)unlocked') Then
        $sSync &= 'Unlocked'
    Else
        $sSync &= 'Locked'
    EndIf

    $aDAC = StringRegExp($sStr, 'DAC.*?(0x[[:xdigit:]]*)', 1)
    If IsArray($aDAC) Then
        $DAC &= Int($aDAC[0])
    Else
        $DAC &= 'Undefined'
    EndIf

    If StringRegExp($sStr, '(?i)no alarms? / no warnings?') Then
        $sStatus &= 'No alram / No warning'
    Else
        Local $aTmp = StringRegExp($sStr, '([^\r]*)[\r\n]*', 3)
        If IsArray($aTmp) Then
            Local $iStart, $iStop
            
            For $i = 0 To UBound($aTmp)-1
                If StringRegExp($aTmp[$i], '/pltf') Then
                    $iStart = $i+4
                    ExitLoop
                EndIf
            Next
            
            For $i = $iStart To UBound($aTmp)-1
                If StringRegExp($aTmp[$i], '/pltf') Then
                    $iStop = $i-2
                    ExitLoop
                EndIf
            Next
            
            For $i = $iStart To $iStop
                Local $aAlarm = StringRegExp($aTmp[$i], '\s*([\w ]+?)\s{2,}', 1)
                If IsArray($aAlarm) Then $sStatus &= $aAlarm[0] & ' / '
            Next
            
            $sStatus = StringTrimRight($sStatus, 3)
        EndIf
    EndIf
    Return $sSync & ', ' & $DAC & ', ' & $sStatus
EndFunc

Posted

Dim $sText1 = '+-----------------------------------+' & @CRLF & _
             '|          SYN Information          |' & @CRLF & _
             '+----------------------+------------+' & @CRLF & _
             '|  Algo version        |     10     |' & @CRLF & _
             '|  Interface version   |      1     |' & @CRLF & _
             '|  Debug mode          |     OFF    |' & @CRLF & _
             '|  DAC value           |   0x07DC   |' & @CRLF & _
             '|  Clock source        |   E1/T1/0  |' & @CRLF & _
             '|  Holdover mode       |     OFF    |' & @CRLF & _
             '|  Activity board      |     ON     |' & @CRLF & _
             '|  Synchro             |  Unlocked  |' & @CRLF & _
             '|  Status              | 0x00000000 |' & @CRLF & _
             '+----------------------+------------+' & @CRLF & _
             '/pltf/syn> sta' & @CRLF & _
             '+--------------------------+' & @CRLF & _
             '|  SYN Status 0x00020008   |' & @CRLF & _
             '+--------------------------+' & @CRLF & _
             '|   WOCVCXOReachMTP1       |' & @CRLF & _
             '|   Some other alarms      |' & @CRLF & _
             '|   s o m e o_TheR         |' & @CRLF & _
             '+--------------------------+' & @CRLF & _
             '/pltf/syn>'
             
Dim $sText2 = '+-----------------------------------+' & @CRLF & _
             '|          SYN Information          |' & @CRLF & _
             '+----------------------+------------+' & @CRLF & _
             '|  Algo version        |     10     |' & @CRLF & _
             '|  Interface version   |      1     |' & @CRLF & _
             '|  Debug mode          |     OFF    |' & @CRLF & _
             '|  DAC value           |   0x07DC   |' & @CRLF & _
             '|  Clock source        |   E1/T1/0  |' & @CRLF & _
             '|  Holdover mode       |     OFF    |' & @CRLF & _
             '|  Activity board      |     ON     |' & @CRLF & _
             '|  Synchro             |  Unlocked  |' & @CRLF & _
             '|  Status              | 0x00000000 |' & @CRLF & _
             '+----------------------+------------+' & @CRLF & _
             '/pltf/syn> sta' & @CRLF & _
             '+--------------------------+' & @CRLF & _
             '|  SYN Status 0x00020008   |' & @CRLF & _
             '+--------------------------+' & @CRLF & _
             '|  No alarms / No warning  |' & @CRLF & _
             '+--------------------------+' & @CRLF & _
             '/pltf/syn>'
             
             
Dim $sMsg = _SyncStatus($sText1)
MsgBox(0x30, 'Title', $sMsg)

$sMsg = _SyncStatus($sText2)
MsgBox(0x20, 'Title', $sMsg)



Func _SyncStatus($sStr)
    
    Local $aDAC, $DAC = 'DAC='
    Local $sStatus = 'Status=', $sSync = 'Sync='
    
    If StringRegExp($sStr, '(?i)unlocked') Then
        $sSync &= 'Unlocked'
    Else
        $sSync &= 'Locked'
    EndIf

    $aDAC = StringRegExp($sStr, 'DAC.*?(0x[[:xdigit:]]*)', 1)
    If IsArray($aDAC) Then
        $DAC &= Int($aDAC[0])
    Else
        $DAC &= 'Undefined'
    EndIf

    If StringRegExp($sStr, '(?i)no alarms? / no warnings?') Then
        $sStatus &= 'No alram / No warning'
    Else
        Local $aTmp = StringRegExp($sStr, '([^\r]*)[\r\n]*', 3)
        If IsArray($aTmp) Then
            Local $iStart, $iStop
            
            For $i = 0 To UBound($aTmp)-1
                If StringRegExp($aTmp[$i], '/pltf') Then
                    $iStart = $i+4
                    ExitLoop
                EndIf
            Next
            
            For $i = $iStart To UBound($aTmp)-1
                If StringRegExp($aTmp[$i], '/pltf') Then
                    $iStop = $i-2
                    ExitLoop
                EndIf
            Next
            
            For $i = $iStart To $iStop
                Local $aAlarm = StringRegExp($aTmp[$i], '\s*([\w ]+?)\s{2,}', 1)
                If IsArray($aAlarm) Then $sStatus &= $aAlarm[0] & ' / '
            Next
            
            $sStatus = StringTrimRight($sStatus, 3)
        EndIf
    EndIf
    Return $sSync & ', ' & $DAC & ', ' & $sStatus
EndFunc
@Authenticity

I've seen you do some sharp stuff, but to me... This one is Impressive!!

Valuater

8)

NEWHeader1.png

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...