![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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" |
|
||||
|
Quote:
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. |
|
||||
|
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} |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|