Sponsored Content
Top Forums Shell Programming and Scripting Is there a BASH script allowing me to grep specifics from /var/log/messages? Post 302994724 by Corona688 on Monday 27th of March 2017 12:06:33 PM
Old 03-27-2017
Code tags for code please.

OK, some sadist printed the dates in MON D HH:MM:SS order and we'll need to convert them before comparing.

Code:
$ awk -v FIRST='03 27 10:24:30' -v LAST='03 27 10:24:35'  'BEGIN {
        split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec", A); # A[1]=Jan, etc
        for(X in A) A[A[X]]=sprintf("%02d",X) # Convert A[1]=Jan to A[Jan]=01
}
{ $1=A[$1] ; $2=sprintf("%02d", $2); } # Substitute two digit months and days into first two fields
($0 >= FIRST) && ($0 <= LAST)' logentryfile

03 27 10:24:31 router kernel: [ 2301.516556] FORWARD-ACCEPTEDIN=eth1 OUT=eth3 MAC=00:0c:29:91:18:81:00:0c:29:02:2c:a0:08:00 SRC=195.165.11.5 DST=195.165.11.70 LEN=69 TOS=0x00 PREC=0x00 TTL=127 ID=5181 PROTO=UDP SPT=59696 DPT=53 LEN=49
03 27 10:24:32 router kernel: [ 2301.619601] FORWARD-DROPPEDIN=eth3 OUT=eth0 MAC=00:0c:29:91:18:95:00:0c:29:46:29:d3:08:00 SRC=195.165.11.70 DST=199.7.83.42 LEN=80 TOS=0x00 PREC=0x00 TTL=127 ID=32098 PROTO=UDP SPT=57894 DPT=53 LEN=60
03 27 10:24:32 router kernel: [ 2301.619641] FORWARD-DROPPEDIN=eth3 OUT=eth0 MAC=00:0c:29:91:18:95:00:0c:29:46:29:d3:08:00 SRC=195.165.11.70 DST=202.12.27.33 LEN=69 TOS=0x00 PREC=0x00 TTL=127 ID=26672 PROTO=UDP SPT=57894 DPT=53 LEN=49
03 27 10:24:34 router kernel: [ 2304.527738] INPUT-DROPPEDIN=eth0 OUT= MAC=ff:ff:ff:ff:ff:ff:00:50:56:c0:00:08:08:00 SRC=192.168.48.1 DST=192.168.48.255 LEN=78 TOS=0x00 PREC=0x00 TTL=64 ID=1792 PROTO=UDP SPT=137 DPT=137 LEN=58

$

Code in red is where you change the date range to what you want. Dates are in MM DD HH:MM:SS order.

Code in blue is the code which does the actual work, everything else is putting the date in proper MM DD HH:MM:SS order.
 

10 More Discussions You Might Find Interesting

1. Solaris

diff b/w /var/log/syslog and /var/adm/messages

hi sirs can u tell the difference between /var/log/syslogs and /var/adm/messages in my working place i am having two servers. in one servers messages file is empty and syslog file is going on increasing.. and in another servers message file is going on increasing but syslog file is... (2 Replies)
Discussion started by: tv.praveenkumar
2 Replies

2. UNIX for Advanced & Expert Users

/var/adm/messages vs /var/log/messages

The /var/adm/messages in Solaris seem to log more system messages/errors compared to /var/log/messages in Linux. I checked the log level in Linux and they seem OK. Is there any other log file that contains the messages or is it just that Linux doesn't log great many things? (2 Replies)
Discussion started by: gomes1333
2 Replies

3. Solaris

Difference between /var/log/syslog and /var/adm/messages

Hi, Is the contents in /var/log/syslog and /var/adm/messages are same?? Regards (3 Replies)
Discussion started by: vks47
3 Replies

4. Shell Programming and Scripting

How can view log messages between two time frame from /var/log/message or any type of log files

How can view log messages between two time frame from /var/log/message or any type of log files. when logfiles are very big and especially many messages with in few minutes, I would like to display log messages between 5 minute interval. Could you pls give me the command? (1 Reply)
Discussion started by: johnveslin
1 Replies

5. UNIX for Dummies Questions & Answers

/etc/sudoers for allowing oracle user to /var/log/messages

So I want the DBA to access /var/log/messages and so I logged in as root and then edited the sudoers file as follows "oracle ALL= (root) /bin/view, /var/log/messages" However when I login as oracle and try "sudo more /var/log/messages" I get Sorry, user oracle is not allowed to... (1 Reply)
Discussion started by: gubbu
1 Replies

6. UNIX for Dummies Questions & Answers

fprintd messages in /var/log/messages

Whenever a user uses su I get the following error messages in /var/log/messages: Nov 23 04:24:55 <REMOVED> abrt: saved core dump of pid 26141 (/usr/libexec/fprintd) to /var/spool/abrt/ccpp-1322018695-26141.new/coredump (753664 bytes) Nov 23 04:24:55 <REMOVED> abrtd: Directory... (3 Replies)
Discussion started by: JakesHat
3 Replies

7. Shell Programming and Scripting

Script to monitor /var/log/messages

Hello All, I want to write a script to monitor my product logs from /var/log/messages and send notifications without using "tail -f" command.Please suggest alternatives and any other tools for monitoring and alerting. Thank You (1 Reply)
Discussion started by: Cva2568
1 Replies

8. Shell Programming and Scripting

Log all the commands input by user at real time in /var/log/messages

Below is my script to log all the command input by any user to /var/log/messages. But I cant achieve the desired output that i want. PLease see below. function log2syslog { declare COMMAND COMMAND=$(fc -ln -0) logger -p local1.notice -t bash -i -- "$USER:$COMMAND" } trap... (12 Replies)
Discussion started by: invinzin21
12 Replies

9. Shell Programming and Scripting

Transfer the logs being thrown into /var/log/messages into another file example /var/log/volumelog

I have been searching and reading about syslog. I would like to know how to Transfer the logs being thrown into /var/log/messages into another file example /var/log/volumelog. tail -f /var/log/messages dblogger: msg_to_dbrow: no logtype using missing dblogger: msg_to_dbrow_str: val ==... (2 Replies)
Discussion started by: kenshinhimura
2 Replies

10. Shell Programming and Scripting

[bash] script is filling up my /var/log

I am trying to create a script that checks if my VPN connection is up and running... Everything seems to work as except but for some reason, the script fills up my /var/log/auth.log with the below information Dec 13 01:07:44 debian sudo: soichiro : TTY=pts/0 ; PWD=/home/soichiro/Desktop ;... (5 Replies)
Discussion started by: soichiro
5 Replies
DDB(8)							    BSD System Manager's Manual 						    DDB(8)

NAME
ddb -- configure DDB kernel debugger properties SYNOPSIS
ddb capture [-M -core] [-N -system] print ddb capture [-M -core] [-N -system] status ddb script scriptname ddb script scriptname=script ddb scripts ddb unscript scriptname ddb pathname DESCRIPTION
The ddb utility configures certain aspects of the ddb(4) kernel debugger from user space that are not configured at compile-time or easily via sysctl(8) MIB entries. To ease configuration, commands can be put in a file which is processed using ddb as shown in the last synopsis line. An absolute pathname must be used. The file will be read line by line and applied as arguments to the ddb utility. Whitespace at the beginning of lines will be ignored as will lines where the first non-whitespace character is '#'. OUTPUT CAPTURE
The ddb utility can be used to extract the contents of the ddb(4) output capture buffer of the current live kernel, or from the crash dump of a kernel on disk. The following debugger commands are available from the command line: capture [-M core] [-N system] print Print the current contents of the ddb(4) output capture buffer. capture [-M core] [-N system] status Print the current status of the ddb(4) output capture buffer. SCRIPTING
The ddb utility can be used to configure aspects of ddb(4) scripting from user space; scripting support is described in more detail in ddb(4). Each of the debugger commands is available from the command line: script scriptname Print the script named scriptname. script scriptname=script Define a script named scriptname. As many scripts contain characters interpreted in special ways by the shell, it is advisable to enclose script in quotes. scripts List currently defined scripts. unscript scriptname Delete the script named scriptname. EXIT STATUS
The ddb utility exits 0 on success, and >0 if an error occurs. EXAMPLES
The following example defines a script that will execute when the kernel debugger is entered as a result of a break signal: ddb script kdb.enter.break="show pcpu; bt" The following example will delete the script: ddb unscript kdb.enter.break For further examples, see the ddb(4) and textdump(4) manual pages. SEE ALSO
ddb(4), textdump(4), sysctl(8) HISTORY
The ddb utility first appeared in FreeBSD 7.1. AUTHORS
Robert N M Watson BUGS
Ideally, ddb would not exist, as all pertinent aspects of ddb(4) could be configured directly via sysctl(8). BSD
December 24, 2008 BSD
All times are GMT -4. The time now is 05:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy