Sponsored Content
Full Discussion: Working with log files
Top Forums Shell Programming and Scripting Working with log files Post 302556923 by melisa.zand on Tuesday 20th of September 2011 03:34:32 PM
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 ?
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
shells(4)							   File Formats 							 shells(4)

NAME
shells - shell database SYNOPSIS
/etc/shells DESCRIPTION
The shells file contains a list of the shells on the system. Applications use this file to determine whether a shell is valid. See getuser- shell(3C). For each shell a single line should be present, consisting of the shell's path, relative to root. A hash mark (#) indicates the beginning of a comment; subsequent characters up to the end of the line are not interpreted by the routines which search the file. Blank lines are also ignored. The following default shells are used by utilities: /bin/bash, /bin/csh, /bin/jsh, /bin/ksh, /bin/ksh93, /bin/pfcsh, /bin/pfksh, /bin/pfsh, /bin/sh, /bin/tcsh, /bin/zsh, /sbin/jsh, /sbin/sh, /usr/bin/bash, /usr/bin/csh, /usr/bin/jsh, /usr/bin/ksh, /usr/bin/ksh93, /usr/bin/pfcsh, /usr/bin/pfksh, /usr/bin/pfsh, and /usr/bin/sh, /usr/bin/tcsh, /usr/bin/zsh, and /usr/sfw/bin/zsh. /etc/shells overrides the default list. Invalid shells in /etc/shells could cause unexpected behavior, such as being unable to log in by way of ftp(1). FILES
/etc/shells list of shells on system SEE ALSO
vipw(1B), ftpd(1M), sendmail(1M), getusershell(3C), aliases(4) SunOS 5.11 20 Nov 2007 shells(4)
All times are GMT -4. The time now is 06:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy