pexpect parse router output - router

I've got a couple of pexpect lines to log onto a cisco router, and issue the show arp command. I then exit the router, having stored the data into the variable myARP (myARP=child.before)
When I then try and loop over the object (for lines in myARP: print(lines), the info is displayed 1 character per line
l
i
k
e
t
h
i
s
Apologies as this is probably a very basic question, but why can't I display as it is shown if I issue the command manually? Is it to do with the streaming nature of the telnet connection? How can this be resolved???

OK fixed - due to pexpects handling of line endings (/n/r) I think. Read Noahs usage docs for more info

Related

DBeaver: Redirect server output to file

I'm using DBeaver to execute a large script file which produces a lot of output (via PostgreSQLs RAISE NOTICE statement). I can see the output in the server output tab, however, the buffer size seems to be limited so a lot of output is lost at the end of the execution.
Is it somehow possible to either increase the server output tab buffer size or redirect the server output directly to a file?
I was experiencing the same issue as you, and I have been unable to find any setting which limits the output length.
In my case, what I eventually discovered was that there was an error in my script which was causing it to fail silently. It looks like part of the output is missing, however it was just the script terminating prematurely.
I encourage you to consider this option, and check your script for errors. Be aware that errors in the script don't appear in the output log.

Batch file doesn't read flags correctly

I've got a little batch file and it looks like this:
.\batchisp.exe –device at32uc3b1512 –hardware usb –operation erase f memory flash blankcheck loadbuffer G3Pro_USB.hex program verify start reset 0
The whole line is fine and works correctly if I run it straight in PowerShell. However, if I run the batch file, it runs this:
.\batchisp.exe ΓÇôdevice at32uc3b1512 ΓÇôhardware usb ΓÇôoperation erase f memory flash blankcheck loadbuffer G3Pro_USB.hex program verify start reset 0
Which does not work, because as you can see, the -'s have changed into ΓÇô's... Can anybody tell me why this is and how to fix it?
This is because the – marks are not - characters. They are actually endashes. These usually are caused by Word's automatic en/emdashing.
Powershell is smart enough to convert the endashes to dashes as "arguments", but cmd is not.
To fix this issue, replace – with -. A regex search/replace that catches all the alternative dash types that works in notepad++ is: [–—‒] to -.

Snort: Reporting packet numbers

I am making use of snort to match packets in pcap file against a set of rules. I want to log the results. I looked at the log file produced at var/log/snort but I want to know that which packet numbers corresponding to the original wireshark pcap file have reported matches. Which command will do that?
You can use the test logger. When running from the command line, add the option '-A test'. The alert's output will have the format
(packet_number) (gid) (sid) (rev).
packet_number corresponds to the pcap's packet number. You can use the other three pieces of information to determine the rule which was triggered.

Send Ctrl+Z to serial port via command line

I am trying to send the following to the COM1 serial port via command line using ECHO or similar (I've also tried downloading a small program called serialsend, but I am stuck with how to send the equivalent of CTRL+Z. This is to send a SMS message via a Siemens TC35 GAM module. I am able to do it via Hyperterminal as a test and it works fine, but I cannot figure out how to send the CTRL+Z at the end to confirm the ned of the message.
This is what I have:
AT
AT+CMGF=1
AT+CMSG="+xxxxxxxxxxx"
HELLO
Now, after Hello, which is the message I want to send, I have to send CTRL+Z. But cannot figure out how to do it, I have tried this:
AT
AT+CMGF=1
AT+CMSG="+xxxxxxxxxxx"
HELLO
\x1A
As I read somehwere that this would be the equivalent of doing it, but it hasnt worked.
Can anyone help me with this? I have found solutions, but they are not command line, which is what I need.
I have also tried using this format:
ECHO AT > COM1:
But as I don't know how to send CTRL+Z I don't know if it is working.
I wrote the free command line program SerialSend that you mentioned. Since this question was originally posted, I've added an extra feature that allows arbitrary byte values to be included (in hex format) in the text you're sending via the serial port. For example, to send Ctrl-Z (26 decimal, 0x1A hex), just use the following command:
SerialSend /hex "\x1a"
Port name/number, baudrate, etc can be configured with additional command line arguments. For example,
SerialSend /baudrate 9600 /devnum 2 /hex "\x1a"
For more details, see the SerialSend home page.
Hope that helps!
Ted
Use this:
port.Write(txt_msgbox.Text + char.ConvertFromUtf32(26));
It works :)
type this command Serial.println((char)26); in Arduino code ... one square box will appear on serial monitor. Copy that square and paste in Notepad++. It will be displayed as SUB with black background. wheneever you want to type cntrl+z, just copy this SUB and paste in serial monitor. It works.

How can I make log4perl output easier to read?

When using log4perl, the debug log layout that I'm using is :
log4perl.appender.D10.layout=PatternLayout
log4perl.appender.D10.layout.ConversionPattern=%d [pid=%P] %p %F{1} (%L) %M %m%n
log4perl.appender.D10.Filter = DebugAndUp
This produces very verbose debug logs, for example:
2008/11/26 11:57:28 [pid=25485] DEBUG SomeModule.pm (331) functions::SomeModule::Test Test XXX was successfull
2008/11/26 11:57:29 [pid=25485] ERROR SomeOtherUnrelatedModule.pm (99999) functions::SomeModule::AnotherTest AnotherTest YYY has faled
This works great, and provides excellent debugging data.
However, each line of the debug log contains different function names, pid length, etc. This makes each line layout differently, and makes reading debug logs much harder than it needs to be.
Is there a way in log4perl to format the line so that the debugging metadata (everything up until the actual log message) be padded at the end with spaces/tabs, and have the actual message start at the same column of text?
You can pad the single fields that make up your entries. For example [pid=%5P] will always give you at least 5 characters for the PID.
The "Quantify Placeholders" section in the docs for Log::Log4perl::Layout gives more details.
There are a couple of ways to go with this, although you have to figure out which one works better for your situation:
Use a different appender if you are working live. Have that appender use a pattern that shows only the information you want. If you're working in a single process, for instance, your alternate appender might leave off the PID and the timestamp. You might only need the file name and line number.
Use %n to put newlines in the right place. That makes it multi-line output that is slightly harder to parse later, but you can choose another sequence for the input record separator (say, a literal "[EOL]") to make it easy to read entry-by-entry.
Log to a database instead of a file. For your reports, select just the columns you want to inspect.
Log everything, but write a filter to go through the log file ad-hoc to display just the parts that you want to see, such as only the debugging messages, the entries between certain times, only the entries involving a file, and so on.