I'm trying to extract texts by using grep on mac
used regex is like this
$grep -E '.+output:([\S\s](?!DEBUG))*?123456789[\S\s]*?END\]' ./AppLog.txt
"123456789" is search id.
then execute this regex,
terminal says "grep: repetition-operator operand invalid."
but In sublime text editor, it executes correctly.
How to fix this error of terminal on mac?
search text example)
I'd like to capture from "output" line to "END" line by UserID.
DEBUG|2018-03-27,14:41:43.089|blabla~~|output:
[START]
=========================================================
00 G_messageText = {"success"}
01 NEW_CS_YN = {"N"}
02 G_messageID = {"0006"}
03 sTaxYn = {"0"}
04 ErrorMsg = {"SUCC"}
05 ErrorCode = {"0"}
06 UserNum = {"111111111"}
07 UserID = {"123456789"} <= search id
08 G_messageTitle = {"notice"}
09 G_messageSeverity = {"2"}
===============================================
[ END ]
DEBUG|2018-03-27,14:41:43.089|blabla~~~
I solved this problem by using "pcregrep".
you can install this program by typing 'brew install pcre'.
thanks.
Related
I want to compare the content of two files in EFI Shell.
I saved the content of pci 05 00 00 in lan-ref.txt
My script looks like this:
echo -off
fs0:
pci 05 00 00 -s 0 > lan.txt
if lan.txt == lan-ref.txt then
reset
else
echo "LAN not found"
endif
I know that the "if lan.txt == lan-ref.txt" is not going to work, I am looking for the correct line to achieve the desired functionality.
Like #prl suggests, combine the comp command and %lasterror%:
comp lan-text lan-ref.txt
if %lasterror% eq 0 then
reset
else
echo "LAN not found"
endif
%lasterror% is equivalent to %errorlevel% in .bat scripts or $? in bourne shells and derivatives.
comp lan-text lan-ref.txt
if %lasterror% ==0 then
reset
else
echo "LAN not found"
endif
I am trying to replicate sg_inq through sg_raw
This is the command used:
inq_cmd := exec.Command("sg_raw", "-r", "512", "/dev/sg0", "12 00 00 00 60 00")
stdoutStderr, err := read_cmd.CombinedOutput()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", stdoutStderr)
Output after execution is
Inq COMMAND :
exit status 1
Invalid command byte '12 00 00 00 60 00'
Inquire COMMAND :
2020/05/28 19:42:48 exit status 1
exit status 1
Invalid command byte '12 00 00 00 60 00'
Usage: sg_raw [OPTION]* DEVICE CDB0 CDB1 ...
Options:
-b, --binary Dump data in binary form, even when writing to stdout
-h, --help Show this message and exit
-i, --infile=IFILE Read data to send from IFILE (default: stdin)
-k, --skip=LEN Skip the first LEN bytes when reading data to send
-n, --nosense Don't display sense information
-o, --outfile=OFILE Write binary data to OFILE (def: hexdump to stdout)
-r, --request=RLEN Request up to RLEN bytes of data (data-in)
-R, --readonly Open DEVICE read-only (default: read-write)
-s, --send=SLEN Send SLEN bytes of data (data-out)
-t, --timeout=SEC Timeout in seconds (default: 20)
-v, --verbose Increase verbosity
-V, --version Show version information and exit
Between 6 and 256 command bytes (two hex digits each) can be specified
and will be sent to DEVICE. Lengths RLEN and SLEN are decimal by
default. Bidirectional commands accepted.
Simple example: Perform INQUIRY on /dev/sg0:
sg_raw -r 1k /dev/sg0 12 00 00 00 60 00
What's wrong in the command? It would be a great help! Thanks in advance!
I need to set some attributes for users and I need to be able to add a hexidecimal value for msExchArchiveGUID and my script errors at this point. I took a manual look and there is a drop down box that you choose from Hexidecimal, Binary, Decimal, or Octal and Hexidecimal is what I need for the value. My value for $Hex = 2a 1b ba 59 ff 5e 00 4c 89 b8 2a af fd c1 fc 23
Below is my script and all the values work except for the msExchArchiveGUID
# Import Information
$Information = Import-Csv "c:\scripts\GUIDIssue\UPNList.csv"
# Convert cloud archive GUID to AD Hex format
foreach ($Info in $Information) {
# Get AD Hex from GUID
[system.guid]$guid = $Info.CloudArchiveGUID
$Hex = ($Guid.ToByteArray() | foreach { $_.ToString('x2') }) -Join ' '
<#
Set Values for the following
Msexchrecipientdisplaytype 1073741824
msExchRecipientTypeDetails 1
msExchRemoteRecipientType 3
msexcharchiveguid “$Hex”
msexcharchivestatus 1
mailnickname “$Info.SAM”
#>
Set-ADUser `
-Identity $Info.SAM -Replace #{
Msexchrecipientdisplaytype="1073741824";
msExchRecipientTypeDetails="1";
msExchRemoteRecipientType="3";
msexcharchivestatus="1";
mailnickname=$Info.SAM;
msexcharchiveguid=$Hex
}
# Sync AD
Start-ADSyncSyncCycle -PolicyType Delta
}
I need a shell script to parse a log file and look for a certain pattern. if that paatern found, then take key values from that line and put it into a csv.
Example:
Here is the log file i have :
*webauthRedirect: Mar 24 08:57:50.903: #EMWEB-6-PARSE_ERROR: webauth_redirect.c:1034 parser exited. client mac= a0:88:b4:d3:55:8c bytes parsed = 0 and bytes read = 213
*webauthRedirect: Mar 24 08:57:50.903: #EMWEB-6-HTTP_REQ_BEGIN_ERR: http_parser.c:579 http request should begin with a character
***ewmwebWebauth1: Mar 04 11:33:46.870: #PEM-6-GUESTIN: pem_api.c:7851 Guest user logged in with user account (mrathi_dev) MAC address 00:1e:65:39:10:8e, IP address 192.168.133.146.**
*ewmwebWebauth1: Mar 04 11:33:46.870: #AAA-5-AAA_AUTH_NETWORK_USER: aaa.c:2178 Authentication succeeded for network user 'mrathi_dev'
*ewmwebWebauth1: Mar 04 11:33:46.858: #APF-6-USER_NAME_CREATED: apf_ms.c:6532 Username entry (mrathi_dev) with length (10) created for mobile 00:1e:65:39:10:8e
*mmListen: Mar 24 08:57:49.030: #APF-6-RADIUS_OVERRIDE_DISABLED: apf_ms_radius_override.c:1085 Radius overrides disabled, ignoring source 4
*webauthRedirect: Mar 24 08:57:47.008: #EMWEB-6-PARSE_ERROR: webauth_redirect.c:1034 parser exited. client mac= 5c:a:5b:60:f1:a7 bytes parsed = 0 and bytes read = 440
*webauthRedirect: Mar 24 08:57:47.008: #EMWEB-6-HTTP_REQ_BEGIN_ERR: http_parser.c:579 http request should begin with a character
*webauthRedirect: Mar 24 08:57:45.453: #EMWEB-6-PARSE_ERROR: webauth_redirect.c:1034 parser exited. client mac= 5c:a:5b:60:f1:a7 bytes parsed = 0 and bytes read = 440
*webauthRedirect: Mar 24 08:57:45.453: #EMWEB-6-HTTP_REQ_BEGIN_ERR: http_parser.c:579 http request should begin with a character
All I am interested in is the #PEM-6-GUESTIN line. I need to take the user id , mac and IP address from this line and put it in a csv. Only log lines with that status are required.
This is my first time working with shell scripts and all your help would be appreciated.
I think it is easier using grep to filter + sed to get groups using regex:
grep "#PEM-6-GUESTIN" log.txt | sed -r "s/.*user account \((.*)\).* MAC address (.*), IP address (.*)\.\*\*.*/\1,\2,\3/"
And the output is in CSV format:
mrathi_dev,00:1e:65:39:10:8e,192.168.133.146
I want to monitor a device that doesn´t support SNMP, so I have tried get a counter via an expect script. This script connects to the device using SSH, logs the output on a file and then it parses the output in order to get the desired counter.
When I execute the script from the console I get the following desired output:
root#box:/path# ./GGSN-PDP-Contexts.expect
.1.3.6.1.4.1.6147.2.1
Integer32
310838
However, when I try to get the result using snmpget it doesn´t work!
root#box:/path# snmpget -m TDP-MIB -v 2c -c TM_Com_Pub localhost .1.3.6.1.4.1.6147.2.1
TDP-MIB::PDPContextsNumber = No Such Instance currently exists at this OID
By the way, this is the relevant configuration at snmpd.conf:
pass .1.3.6.1.4.1.6147.2.1 /usr/bin/expect /path/GGSN-PDP-Contexts.expect
And this is the expect script that I'm using:
#!/usr/bin/expect -f
# Constants
set user "user"
set device "10.10.222.176"
set pass "blablabla"
set timeout -1
set prompt "GGSN-LV02#"
set file "./GGSN-PDP-Contexts.log"
# Options
match_max 100000
log_user 0
# Access to device
spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $user#$device
expect "*?assword:*"
send -- "$pass\r"
# Commands execution
expect -exact "$prompt"
send -- "display pdp-number\r"
log_file -a $file
# Logging
expect -exact "$prompt"
log_file
send -- "quit\r"
# Get the value
set result [exec cat $file | grep "ALL GTP" | cut -d " " -f14]
set value [format %d $result]
# Print the value
puts ".1.3.6.1.4.1.6147.2.1"
puts "Integer32"
puts $value # If I replace the $value with a number, it doesn't work either
# Erase log file
exec rm $file
close
Could you bring me any hint? Thanks in advance!
EDIT:
In addition, these are the last lines of snmpget's debug output:
trace: snmp_comstr_parse(): snmp_auth.c, 135:
dumph_recv: SNMP version
dumpx_recv: 02 01 01
dumpv_recv: Integer: 1 (0x01)
trace: snmp_comstr_parse(): snmp_auth.c, 147:
dumph_recv: community string
dumpx_recv: 04 0A 54 4D 5F 43 6F 6D 5F 50 75 62
dumpv_recv: String: TM_Com_Pub
trace: _snmp_parse(): snmp_api.c, 4149:
dumph_recv: PDU
trace: snmp_pdu_parse(): snmp_api.c, 4255:
dumpv_recv: Command RESPONSE
trace: snmp_pdu_parse(): snmp_api.c, 4336:
dumph_recv: request_id
dumpx_recv: 02 04 3B 9E CF 74
dumpv_recv: Integer: 1000263540 (0x3B9ECF74)
trace: snmp_pdu_parse(): snmp_api.c, 4347:
dumph_recv: error status
dumpx_recv: 02 01 00
dumpv_recv: Integer: 0 (0x00)
trace: snmp_pdu_parse(): snmp_api.c, 4358:
dumph_recv: error index
dumpx_recv: 02 01 00
dumpv_recv: Integer: 0 (0x00)
trace: snmp_pdu_parse(): snmp_api.c, 4376:
dumph_recv: VarBindList
trace: snmp_pdu_parse(): snmp_api.c, 4406:
dumph_recv: VarBind
trace: snmp_parse_var_op(): snmp.c, 166:
dumph_recv: Name
dumpx_recv: 06 09 2B 06 01 04 01 B0 03 02 01
dumpv_recv: ObjID: TDP-MIB::PDPContextsNumber
trace: snmp_pdu_parse(): snmp_api.c, 4415:
dumph_recv: Value
TDP-MIB::PDPContextsNumber = No Such Instance currently exists at this OID
Also, this is my current MIB:
TDP-MIB DEFINITIONS ::= BEGIN
IMPORTS
MODULE-IDENTITY, OBJECT-TYPE, Integer32, enterprises
FROM SNMPv2-SMI
OBJECT-GROUP FROM SNMPv2-CONF;
TDP MODULE-IDENTITY
LAST-UPDATED "201210080000Z" -- 8/oct/2012
ORGANIZATION "TELEFONICA"
CONTACT-INFO "Authors: Hernan Romano / Antonio Ocampo
Email: h.romanoc#pucp.edu.pe / aocampo#pucp.edu.pe"
DESCRIPTION "MIB para gestionar los equipos que carecen de SNMP"
REVISION "201210080000Z" -- 08/oct/2012
DESCRIPTION "Revision 2.1"
::= { enterprises 6147 }
Nokia OBJECT IDENTIFIER ::= { TDP 1 }
Huawei OBJECT IDENTIFIER ::= { TDP 2 }
TDPMIBConformance OBJECT IDENTIFIER ::= { TDP 3 }
ClearCodeGroup1 OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-only
STATUS current
DESCRIPTION "Clear Code Group 1"
::= { Nokia 1 }
PDPContextsNumber OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-only
STATUS current
DESCRIPTION "PDP Contexts Number"
::= { Huawei 1 }
TDPMIBGroup OBJECT IDENTIFIER
::= { TDPMIBConformance 1 }
--grupoTDP OBJECT-GROUP
-- OBJECTS {
-- ClearCodeGroup1,
-- PDPContextsNumber
-- }
-- STATUS current
-- DESCRIPTION "Objetos para el monitoreo de los equipos que carecen de SNMP"
-- ::= { TDPMIBGroup 1 }
END
Finally solved :) The trouble was the path file.
Instead of relative path:
set file "./GGSN-PDP-Contexts.log"
I put the absolute path:
set file "/FULL_PATH/GGSN-PDP-Contexts.log"
and snmpget works!!
root#box:/path# snmpget -m TDP-MIB -v 2c -c TM_Com_Pub localhost .1.3.6.1.4.1.6147.2.1
TDP-MIB::PDPContextsNumber = INTEGER: 319291