The UNIX and Linux Forums  

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
Hey Perl Gurus neil1983 Shell Programming and Scripting 1 12-06-2007 10:03 AM
SED GURUS - Help! Simerian Shell Programming and Scripting 2 11-03-2006 10:28 AM
Date format - Shell scripting gurus please help geomonap Shell Programming and Scripting 3 02-02-2006 05:15 AM
Help with shell script - Unix Gurus calling ravred Shell Programming and Scripting 4 01-26-2006 04:20 AM
Any RF unix gurus out there? Subrosa UNIX for Advanced & Expert Users 5 10-16-2003 04:08 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 04-21-2006
Fred Fred is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 2
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 (permalink)  
Old 04-21-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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 (permalink)  
Old 04-21-2006
Fred Fred is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 2
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 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 .

/F
  #4 (permalink)  
Old 04-21-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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
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 04:08 AM.


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