Working with log files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Working with log files
# 1  
Old 09-20-2011
Working with log files

I wrote a bash script to extract a few Items like the IP addresses that makes the most number of connection attempts, now I want to limit all of this within a time range , lets say the last X days/hours.

Example of what I wrote :

-G: Which IP address makes the most number of connection attempts?

Code:
if [ "$3" = "-G" ]; then 
 I won't write the whole code ! 
echo "IP address makes the most number of connection attempts: \n"
awk '{print $1}' $4 | sort | uniq -c | sort -r -n | awk '{print $2 "\t" $1}' >> Connections 
cat Connections | head -$2 
 rm Connections

now I want to add this Items

-O: Limit it to last number of hours

-P: Limit it to the last number of days

and I run it like this : sh -O -P -G *.log

example log file:

213.46.27.204 - - [15/Sep/2011:22:55:21 +0100]
213.46.27.204 - - [16/Sep/2011:22:55:21 +0100]
213.46.27.204 - - [17/Sep/2011:22:55:21 +0100]
213.46.27.204 - - [18/Sep/2011:22:55:21 +0100]
213.46.27.204 - - [19/Sep/2011:22:55:21 +0100]

please answer just with bash script not python or perl

---------- Post updated at 02:34 PM ---------- Previous update was at 03:44 AM ----------

any ideas ?
# 2  
Old 09-20-2011
Date and time calculations in shell scripts can be very complex.

Check this link:
https://www.unix.com/unix-dummies-que...html#post16559
# 3  
Old 09-20-2011
Dear matarsak.

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirecting log files to null writing junk into log files

Redirecting log files to null writing junk into log files. i have log files which created from below command exec <processname> >$logfile but when it reaches some size i am redirecting to null while process is running like >$logfile manually but after that it writes some junk into... (7 Replies)
Discussion started by: greenworld123
7 Replies

2. Red Hat

Log rotation not working in Centos 7.2

All, I am facing an issue as log rotation not working for me as expected for tomcat in centos 7.2. I configured log rotation command in crontab */5 * * * * root /usr/sbin/logrotate /etc/logrotate.conf >/dev/null 2>&1 I am trying to rotate below tomcat logs owned by application... (0 Replies)
Discussion started by: shekar777
0 Replies

3. Shell Programming and Scripting

[awk] working with two files

Hello guys, I have little to no experience working with two files in awk and hope you can help me with a problem that may be easy for you to solve... awk -v cut1="$var1" -v cut2="$var2" '{split($0, arr1); for(i=1;i<=NF;i++) if (arr1 < cut1) print arr1, NR, i}' file1 file2 The above code is... (4 Replies)
Discussion started by: origamisven
4 Replies

4. Shell Programming and Scripting

Working on Files

Hi, One of the program creating a file with the following information. $cat a.txt 1, AAA, 234 $ and I wrote a script whenever any of the the file exists with data then it will send a email to me. If I start the job second time, then the as per the logic it is sending the same data, I... (3 Replies)
Discussion started by: Alex_Smith
3 Replies

5. 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

6. AIX

exclude files not working

HI, I have upgraded nim master and client to TL8,SP6. Now when the mksysb backup ran from master,it is not excluding directories specified in /etc/exclude.rootvg in the client.Instead,mksysb is getting created for all the file systems in the rootvg. This problem only appeared after the TL... (3 Replies)
Discussion started by: to_bsr
3 Replies

7. Shell Programming and Scripting

uuencode not working for multiple files

Hi, I have gone through the other related post but are of no help for me I am sending multiple files as attachement. The first file comes fine as an attachement but the other files are coming as binary. For people with older version of email software they can see all attachements but... (1 Reply)
Discussion started by: pinnacle
1 Replies

8. UNIX for Dummies Questions & Answers

RedirectMatch not working for files

Hi I am trying to redirect all webpages within a directory on my site to another website. I can only get this to work for directories only, not actual files. The following scenarios work: http://www.mysite.com/folder1/folder3 redirects to http://www.newsite.com/redirectpage.jsp ... (0 Replies)
Discussion started by: geoscience
0 Replies

9. Shell Programming and Scripting

working with files

Hi All, Can u plz tell me how to ensure row count. input file /app/PNYCOINF01/opera/operaprd/Data/SENTRY_BSL2_COLLRECEIVEPOS_AM_20070716.dat checkFile: The input file exists checkFile: Checking for existing copy of output file... (4 Replies)
Discussion started by: balireddy_77
4 Replies

10. Shell Programming and Scripting

bash script working for small size files but not for big size files.

Hi, I have one file stat. Stat file contents are as follows: for example. H50768020040913,00260100,507680,13,0000000643,0000000643,00000,0000 H50769520040808,00260100,507695,13,0000000000,0000000000,00000,0000 H50770620040611,00260100,507706,13,0000000000,0000000000,00000,0000 Now i... (1 Reply)
Discussion started by: davidpreml
1 Replies
Login or Register to Ask a Question