Sponsored Content
Top Forums Shell Programming and Scripting Is there a BASH script allowing me to grep specifics from /var/log/messages? Post 302994714 by vgplayer54 on Monday 27th of March 2017 10:25:05 AM
Old 03-27-2017
Sure, here is the code I have so far that is not working:

Code:
#!/bin/bash

read -p "Enter month (first 3 letters): " month

read -p "Enter day of month: " day

read -p "Enter starting time (HH:MM:SS): " stime

read -p "Enter ending time (HH:MM:SS): " ftime

read -p "Enter chain: " chain

read -p "Enter any other modifiers (TTL, SRC, DSP, SPT, DPT, IN, OUT, etc): " modifier

if [ -z "$month" ]; then
    month='IN='
fi

if [ -z "$chain" ]; then
    chain='IN='
fi

if [ -z "$modifier" ]; then
    modifier='IN='
fi

if [ -z "$stime" ] && [ -z "$ftime" ]; then

cat /var/log/messages | grep -i "$month $day" | grep -i $chain | grep -i $modifier

else

cat /var/log/messages | grep -i "$month $day" | grep -i $chain | grep -i $modifier | sed -n "/$stime/,/$ftime/p"

fi

And here is an example of the /var/log/messages traffic:

Code:
Mar 27 10:24:29 router kernel: [ 2298.775662] 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=1791 PROTO=UDP SPT=137 DPT=137 LEN=58 
Mar 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 
Mar 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 
Mar 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 
Mar 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 
Mar 27 10:24:35 router kernel: [ 2305.243755] FORWARD-ACCEPTEDIN=eth3 OUT=eth1 MAC=00:0c:29:91:18:95:00:0c:29:46:29:d3:08:00 SRC=195.165.11.70 DST=195.165.11.5 LEN=69 TOS=0x00 PREC=0x00 TTL=127 ID=8386 DF PROTO=UDP SPT=53 DPT=59696 LEN=49 
Mar 27 10:24:35 router kernel: [ 2305.244995] 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=5182 PROTO=UDP SPT=57560 DPT=53 LEN=49 
Mar 27 10:24:35 router kernel: [ 2305.245255] 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=192.58.128.30 LEN=69 TOS=0x00 PREC=0x00 TTL=127 ID=7802 PROTO=UDP SPT=58259 DPT=53 LEN=49 
Mar 27 10:24:35 router kernel: [ 2305.277867] 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=1793 PROTO=UDP SPT=137 DPT=137 LEN=58 
Mar 27 10:24:36 router kernel: [ 2306.030264] 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=1794 PROTO=UDP SPT=137 DPT=137 LEN=58 
Mar 27 10:24:36 router kernel: [ 2306.249173] 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=5183 PROTO=UDP SPT=57560 DPT=53 LEN=49 
Mar 27 10:24:37 router kernel: [ 2306.885204] 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=1795 PROTO=UDP SPT=137 DPT=137 LEN=58 
Mar 27 10:24:37 router kernel: [ 2307.264584] 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=5184 PROTO=UDP SPT=57560 DPT=53 LEN=49 
Mar 27 10:24:38 router kernel: [ 2307.634718] 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=1796 PROTO=UDP SPT=137 DPT=137 LEN=58 
Mar 27 10:24:38 router kernel: [ 2308.384824] 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=1797 PROTO=UDP SPT=137 DPT=137 LEN=58 
Mar 27 10:24:39 router kernel: [ 2309.279134] 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=5185 PROTO=UDP SPT=57560 DPT=53 LEN=49 
Mar 27 10:24:39 router kernel: [ 2309.339155] 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=1798 PROTO=UDP SPT=137 DPT=137 LEN=58 
Mar 27 10:24:40 router kernel: [ 2309.773505] 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=198.41.0.4 LEN=69 TOS=0x00 PREC=0x00 TTL=127 ID=10024 PROTO=UDP SPT=58259 DPT=53 LEN=49 
Mar 27 10:24:40 router kernel: [ 2310.089359] 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=1799 PROTO=UDP SPT=137 DPT=137 LEN=58 
Mar 27 10:24:41 router kernel: [ 2310.839629] 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=1800 PROTO=UDP SPT=137 DPT=137 LEN=58 
Mar 27 10:24:42 router kernel: [ 2311.991505] 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=1801 PROTO=UDP SPT=137 DPT=137 LEN=58 
Mar 27 10:24:43 router kernel: [ 2312.741286] 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=1802 PROTO=UDP SPT=137 DPT=137 LEN=58 
Mar 27 10:24:43 router kernel: [ 2313.292604] 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=5186 PROTO=UDP SPT=57560 DPT=53 LEN=49 
Mar 27 10:24:43 router kernel: [ 2313.396563] 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=69 TOS=0x00 PREC=0x00 TTL=127 ID=32099 PROTO=UDP SPT=58259 DPT=53 LEN=49 
Mar 27 10:24:43 router kernel: [ 2313.396740] 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=193.0.14.129 LEN=69 TOS=0x00 PREC=0x00 TTL=127 ID=26639 PROTO=UDP SPT=58259 DPT=53 LEN=49 
Mar 27 10:24:43 router kernel: [ 2313.493634] 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=1803 PROTO=UDP SPT=137 DPT=137 LEN=58 
Mar 27 10:24:45 router kernel: [ 2315.046166] 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=1804 PROTO=UDP SPT=137 DPT=137 LEN=58 
Mar 27 10:24:46 router kernel: [ 2315.796555] 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=1805 PROTO=UDP SPT=137 DPT=137 LEN=58 
Mar 27 10:24:46 router kernel: [ 2316.546721] 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=1806 PROTO=UDP SPT=137 DPT=137 LEN=58 
Mar 27 10:24:47 router kernel: [ 2317.292821] 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=5187 PROTO=UDP SPT=64648 DPT=53 LEN=49 
root@router:/home/ajfoncec/Checkpoint_4_Scripts#


Last edited by Corona688; 03-27-2017 at 12:57 PM..
 

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
All times are GMT -4. The time now is 07:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy