LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 06-09-2010, 09:14 AM   #1
lowcalspam
LQ Newbie
 
Registered: Jun 2010
Posts: 2

Rep: Reputation: 0
Scripting Question


Hey everyone,

So I've been writing a script that does a Lynx grab from a list of port numbers and IP's from SANS Internet Storm website. I then sed it down to the format that I want and dump each of those into text files. (See code below)

for i in `lynx -source "http://isc.sans.edu/feeds/topips.txt"|sed -e "s/\t/,/g"|cut -d "," -f1`; do echo "$i"; done > TOP_IPS_`date +20%y-%m-%d`.txt

for i in `lynx -source "http://isc.sans.edu/trendascii.html"|sed '/SANS/d'|sed '/Commons ShareAlike/d'|sed '/#/d'|sed '/Creative/d'|sed '/(c)/d'| sed -e "s/\t/,/g"|cut -d "," -f1`; do echo "$i"; done > TOP_PORTS`date +20%y-%m-%d`.txt

So, then what I'm wanting to do is have a loop go through and pull each of the IP's from the file(s) above and do a grep on certain log files for each IP, and likewise do the same thing from the port listing file that I have created. I have been thinking that creating an array in bash would be the way to go, but I'm not having any luck. Anyone have any ideas how to accomplish this?

Thanks a ton in advance.
 
Old 06-09-2010, 09:41 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,169

Rep: Reputation: 1776Reputation: 1776Reputation: 1776Reputation: 1776Reputation: 1776Reputation: 1776Reputation: 1776Reputation: 1776Reputation: 1776Reputation: 1776Reputation: 1776
Ok ... so as your new the first thing you need to use when asking your questions are the code tags [code] (see advanced button to help with these). Just helps for us to read what code you have written.

Secondly, I find it helps if you give us the following:

1. What the input files look like that we need to get data from
2. What have you tried so far?

You mentioned you haven't had any luck so maybe one of the people here will see where you went wrong
 
Old 06-09-2010, 10:07 AM   #3
lowcalspam
LQ Newbie
 
Registered: Jun 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Sorry about that, I will correct my actions thanks for the pointers.

The input file is merely a text file with port numbers listed for instance:

304
1010
1020

There are no quotes, commas, tabs, etc. Each line merely has a new port number in the ports file. The source file is named: 1TOP_PORTS__`date +20%y-%m-%d`.txt

So, here is what I have tried:




Code:
for i in `lynx -source "http://isc.sans.edu/trendascii.html"|sed '/SANS/d'|sed '/Commons ShareAlike/d'|sed '/#/d'|sed '/Creative/d'|sed '/(c)/d'| sed -e "s/\t/,/g"|cut -d "," -f1`; do echo "$i"; done > 1TOP_PORTS__`date +20%y-%m-%d`.txt


IFS='
'
file=( $( < 1TOP_*.txt) )
echo $file

cat global-*-ipt.log | grep "DPT\=$file"
Right now, it's grep'ing fine for the first line for the port number form the source file, but I'm drawing a blank on how to get it to iterate to the next port number from the source file.
 
Old 06-09-2010, 12:38 PM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Quote:
Originally Posted by lowcalspam View Post
Code:
for i in `lynx -source "http://isc.sans.edu/trendascii.html"|sed '/SANS/d'|sed '/Commons ShareAlike/d'|sed '/#/d'|sed '/Creative/d'|sed '/(c)/d'| sed -e "s/\t/,/g"|cut -d "," -f1`; do echo "$i"; done > 1TOP_PORTS__`date +20%y-%m-%d`.txt


IFS='
'
file=( $( < 1TOP_*.txt) )
echo $file

cat global-*-ipt.log | grep "DPT\=$file"
Right now, it's grep'ing fine for the first line for the port number form the source file, but I'm drawing a blank on how to get it to iterate to the next port number from the source file.
Hi,

if I understand correctly then the for loop works fine and you just need to step through every line in the generated file, right? Well, the standard approach for such a task would be
Code:
while read line
do
echo $line
# do other stuff like
grep "DPT\=$line" global-*-ipt.log # don't need the cat to grep
done < /path/to/file
Is this what you need?

Last edited by crts; 06-09-2010 at 12:40 PM.
 
Old 06-09-2010, 03:41 PM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 10,882
Blog Entries: 1

Rep: Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307
Hi,

Welcome to LQ!

As you have been instructed that we can aid you when you help yourself to a solution. You should provide us with what you have attempted along with relative data, code and then maybe someone will be able to assist. Plus an additional reminder to use the vbcode tags # or quote.

'How to Ask Questions the Smart Way' would be one link you should look at to help us to help you in the future. Below are several good reference links that may aid you;

Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Utimate Linux Newbie Guide
LinuxSelfHelp
Getting Started with Linux
Bash Reference Manual <<<<<< Look here
Advanced Bash-Scripting Guide <<<<<< Look here
Linux Home Networking
Virtualiation- Top 10


The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
scripting question Jurrian Linux - Newbie 5 10-21-2008 05:15 AM
Scripting question msandford Linux - Newbie 4 09-05-2005 10:23 AM
Question about scripting RitzContent Programming 18 11-23-2004 10:34 AM
Scripting Question... Darklight451 Linux - Newbie 3 09-23-2004 05:03 PM
Scripting question glock19 Linux - Software 2 09-05-2003 12:45 AM


All times are GMT -5. The time now is 05:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration