A q for the gurus. Filehandling & reacting to events (?)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A q for the gurus. Filehandling & reacting to events (?)
# 1  
Old 04-21-2006
A q for the gurus. Filehandling & reacting to events (?)

Ok, since i am scripting first-timer i want to apology in advance if any of my ideas are way off.

What i am trying to achieve is a script that can listen for alerts from snort. When snort triggers an alert then i want my script to do nothing for X seconds, and after that period of time i want the script to copy a bunch of files (tcpdump-files and possibly the snort-log) to a newly created folder.

So in some sort of meta-code i am trying to achieve something like this:

If/When snort triggers an alert
{
Wait 5 minutes
Create a new folder /A/B/N (here i would need to name the folder in YYMMDD-HHMM format i believe)
Copy all files at /S/D/ to /A/B/N
Copy file F to /A/B/N
}

So the next time snort triggers an alert this script would create yet another folder and copy the files i want to that folder.

So, does anyone of you know if this is possible using shellscript?
If it is, can anyone perhaps show an example or help me in any way ?

Thanks in advance !

/F
# 2  
Old 04-21-2006
Definitely possible. Use the date command to get the YYMMDD-HHMM format. Then use cp to copy the files across. Something like this:

Code:
while true; do
   if [ alert_triggerred -eq 1 ]; then
      sleep 300   # sleep for five minutes
      datestamp=$(date +%y%m%d%H%M)
      mkdir /path/to/dest/$datestamp  # create directory as reqd.
      # you can also run anything else that you require here
      cp /path/to/source/* /path/to/dest/$datestamp/  # copy reqd. files
      cp /path/to/single_file /path/to/dest/$datestamp/
      # or here or anywhere else in the loop
   fi
done

# 3  
Old 04-21-2006
Wow!

I managed to get the file and folder handling working. And when i came back to this computer i saw that your code snippet did the same thing in about one third of the number of lines that I had Smilie so needles to say im going to use your version.

Thank you very much for your help. (The feeling when these things finally work as intended is ...sweet).

There's only one tiny problem left.
Does anyone know how i actually manage to get it to kick off when snort alerts? After a few tests I dont seem to get that part working.

i.e I dont really understand the part: "alert_triggered -eq 1".

Would it require me to set up some variable(alert_triggered) that is hooked on to snort and listens for alerts? (Or is this alerter functionality already built-in and waiting for me somewhere in linux)

Any ideas on how this can be done? (Or did i miss something in the example?)
If i need to somehow hook a listener to snort...well im kind of lost so examples will be immensely appreciated Smilie .

/F
# 4  
Old 04-21-2006
Quote:
Originally Posted by Fred
i.e I dont really understand the part: "alert_triggered -eq 1".

Would it require me to set up some variable(alert_triggered) that is hooked on to snort and listens for alerts? (Or is this alerter functionality already built-in and waiting for me somewhere in linux)
By alert_triggered -eq 1, I just meant that if the alert is triggered. See, I have never used snort, I don't even know what it does. So hooking up the alert with your script will have to be done by you, or may be someone else here has used snort and will help you.

Cheers
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question to gurus about sed.

Hi Folks. I need change something into file and after all manipulation I need delete only last COMMA into this piece of code -> GROUP 1 ( '/oralog1/ORAPRD/log01a.dbf', '/oralog2/ORAPRD/log01b.dbf' ) SIZE 512M, GROUP 2 ( '/oralog1/ORAPRD/log02a.dbf', ... (12 Replies)
Discussion started by: beckss
12 Replies

2. UNIX for Dummies Questions & Answers

Calling all the awk gurus out there.

Hi all, I just signed up to the forums, although, I have lurked on here for awhile. Anyways, my issue is I am trying to get awk to spit out something I can use without having to spend hours in excel hell haha. So, I used sed to replace the spaces with semicolons and redirected that to a file. ... (6 Replies)
Discussion started by: savigabi
6 Replies

3. Web Development

PHPMaker 9 Help with Server Events & Filter

Hello, I need some help with PHPMaker 9 "Server Events". trying to do a simple filter but my lack of knowledge of PHP & Mysql is getting me in a jam. I have 2 tables: MyMainTable = which has all individual records for different people and Users = the security table that also has... (0 Replies)
Discussion started by: vestport
0 Replies

4. Shell Programming and Scripting

Unix/Linux gurus...here is Q 4u

Suppose I have two files 1.txt and 2.txt. My aim is to find (Total execution time/Number of executions) then sort the result as in decreasing order. Can anyone provide me any shell/perl/awk script or a Command to do that in faster way ? 1.txt : =============================== Number of... (4 Replies)
Discussion started by: Rahulpict
4 Replies

5. Shell Programming and Scripting

Hey Perl Gurus

Hey guys im trying to get this if statement to work and i dont know whats wrong. can anybody help? if($author=~/\A+\Z/i)&&(length($author!=0)) { print " $author validation correct" } elsif($author!=~/\A+\Z/i)&&(length($author=0)) { $author='BLANK'; } else { ... (1 Reply)
Discussion started by: neil1983
1 Replies

6. Shell Programming and Scripting

SED GURUS - Help!

I wish to substituite a string on each line but ONLY if it appears within double-quotes: this_string="abc#def#geh" # Comment here I wish to change the "#" characters within the double quoted string to "_": this_string="abc_def_geh" # Comment here ... but as you see, the "comment" hash... (2 Replies)
Discussion started by: Simerian
2 Replies

7. UNIX for Advanced & Expert Users

Any RF unix gurus out there?

I am having a problem here. We are having several problems in regards to hung process's on unix (HPUX box), caused by my RF equipment (Mobile data capture units). these contact the host via a simply telnet session and locks the system? Is it a timeout problem as the timeout is disabled on the host. (5 Replies)
Discussion started by: Subrosa
5 Replies
Login or Register to Ask a Question