The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help me in sending parameters from sqlplus script to unix shell script Hara Shell Programming and Scripting 2 01-29-2008 03:31 PM
Shell Script: want to insert values in database when update script runs ring Shell Programming and Scripting 1 10-25-2007 03:06 AM
here document to automate perl script that call script hogger84 Shell Programming and Scripting 3 10-22-2007 10:15 AM
returning to the parent shell after invoking a script within a script gurukottur Shell Programming and Scripting 5 09-26-2006 07:05 AM
return valuse from child script to parent script borncrazy Shell Programming and Scripting 1 08-20-2004 03:39 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-30-2007
razoreqx razoreqx is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 3
AWK script

I am by no means a programmer but I would love to learn. Problem is I have a real problem that needs a script asap.

I need to write a script that can parse a logfile and pull out unique ip address from the source address column and create a file with the name of the ip address as the filename. Then when a destination IP addresses matches the source address of a file it appends that unique destination address and port to that file.

So what im trying to do is create a file for each infected computer and append inside that file all the hosts they are trying to infect.

Here is a snippet of the logfile.

-----------------------------------------------------------------------
2007-08-30 11:31:52,Syslog.Info,10.254.5.164,"26838: Aug 30 11:31:50: %SEC-6-IPACCESSLOGP: list 199 denied tcp 10.5.167.246(4086) -> 10.184.232.130(1433), 1 packet"
2007-08-30 11:31:52,Syslog.Info,10.254.6.24,"432042: pik-router: Aug 30 11:31:52: %SEC-6-IPACCESSLOGP: list 199 denied tcp 10.253.220.42(1509) -> 10.25.50.154(1433), 1 packet"
2007-08-30 11:31:52,Syslog.Info,10.254.3.176,"492962: lco-router: Aug 30 11:31:52: %SEC-6-IPACCESSLOGP: list 199 denied tcp 10.3.179.232(2661) -> 10.45.253.12(1433), 1 packet"
2007-08-30 11:31:52,Syslog.Info,10.254.5.240,"4841: .Aug 30 11:31:52: %SEC-6-IPACCESSLOGP: list 199 denied tcp 10.253.218.171(1532) -> 10.246.248.36(1433), 1 packet"
2007-08-30 11:31:52,Syslog.Info,10.254.5.240,"4842: .Aug 30 11:31:53: %SEC-6-IPACCESSLOGP: list 199 denied tcp 10.253.218.171(1564) -> 10.25.5.144(1433), 1 packet"
2007-08-30 11:31:52,Syslog.Info,172.20.7.13,"495539: ba2-router: Aug 30 11:31:52: %SEC-6-IPACCESSLOGP: list 199 denied tcp 10.253.221.172(2346) -> 10.30.165.137(445), 1 packet"
2007-08-30 11:31:52,Syslog.Info,10.254.0.244,"473266: nac-router: Aug 30 11:31:52: %SEC-6-IPACCESSLOGP: list 199 denied tcp 10.0.247.183(3230) -> 10.155.217.188(1433), 1 packet"
  #2 (permalink)  
Old 08-30-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
don't assume we all know the structure of your log file....
what is the source and what is the destination addresses in the given sample?
given a posted sample log, what is the desired output?
  #3 (permalink)  
Old 08-30-2007
razoreqx razoreqx is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 3
Quote:
Originally Posted by vgersh99 View Post
don't assume we all know the structure of your log file....
what is the source and what is the destination addresses in the given sample?
given a posted sample log, what is the desired output?
Sorry good point.

After the "list 199 denied" the first IP address is the source and the 2nd IP address is the destination.

the output im looking for is a file created for each unique "source" and an append to that file of each destination that matches each unique source.
  #4 (permalink)  
Old 08-31-2007
razoreqx razoreqx is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 3
So far i have come up with this but its not working.

#!/bin/ksh
PATH=$PATH
vDIR_OUT=/cygdrive/c/tmp
vLOG_OUT=${vDIR_OUT}/ipmon.out
vSYSLOG=/cygdrive/v/Routers.txt
vSYSLOG_OUT=${vDIR_OUT}/syslog.log.new
vCOUNTER_FILE=${vDIR_OUT}/counter.out

export PATH vDIR_OUT vLOG_OUT vSYSLOG_OUT vCOUNTER_FILE FINAL


#############################################
## Create a counter to get only the new
## lines from the syslog.log.
#############################################

#print "\nStarting Counter, please be patient...\n"

#FINAL=$(cat ${vCOUNTER_FILE})
#typeset -i START=0
#
#cat ${vSYSLOG}|while read vLINE
#do
#((START=START+1))
#if [[ ${START} -gt ${FINAL} ]]
#then
##print "${vLINE}"
#fi
#done > "${vSYSLOG_OUT}"
#print "${START}" #> "${vCOUNTER_FILE}"

#################################
## Now collect new data into
## a folder for each IP address.
#################################

awk '/tcp/ && !/awk/ {printf("%s %s\n", $(NF-4),$(NF-2))}' ${vSYSLOG_OUT} |sort -u> ${vLOG_OUT} 2>&1
while read -r vIP
do
vSOURCE_IP=$(print ${vIP}|awk -F"(" '{print $1}')
[ ! -d ${vSOURCE_IP} ] && mkdir ${vSOURCE_IP}
[ -d ${vSOURCE_IP} ] && print "Folder ${vSOURCE_IP} already exist"
print "Appending ${vIP} to ${vSOURCE_IP}"
print "${vIP}"|awk -F, '{print $1,$2}' >> ${vSOURCE_IP}/${vSOURCE_IP}.txt
done < ${vLOG_OUT}
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0