Email alert when client in blacklist joins network

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Email alert when client in blacklist joins network
# 1  
Old 04-18-2016
Email alert when client in blacklist joins network

I have a textfile with a list of strings I want to monitor in my network.

alertlist:
Code:
hans
franz
tanz

So it can output for me whenever the a strings it matched:
Code:
#!/bin/sh
while : ; do
    testfile="/var/media/ftp/alertlist.txt"
  [[ -f "$testfile" ]] && echo "${testfile##*/} exists." ||  echo "${testfile##*/} does not exist."
  while /var/media/ftp/look.sh active | grep -i -f  /var/media/ftp/alertlist.txt
  do
???
        sleep 4 
    done
    sleep 4
done&

Now what I want is eh a notification, whenever the state changes, example, hans joins, franz leaves franz and tanz joins etc.

not when found or nor, only when the situation changes

how can I do this while keepin the I/O to the flashdrives to a minimum?

Last edited by lowmaster; 04-22-2016 at 09:29 AM.. Reason: making the question more simple
# 2  
Old 04-18-2016
Hmm. Quick question - if a process or user is blacklisted correctly - iptables in linux can do this for you - then it never, ever get your system to start with. Why do you allow them to get going on your system to start with??

The tool to block access by IP is OS dependent. I gave a linux example.
# 3  
Old 04-18-2016
this is more for that I'm informed if specific people are coming or nearby to my place via wifi

okay blacklist is misleading here, it is more an "alert list"
# 4  
Old 04-22-2016
I have optimized the question. I hope it is clearer now...

I just want to do soemthing in this loop, if one the strings in the textfile apear in the shell output the first time, or when they disappear, or re appear..
# 5  
Old 04-22-2016
Quote:
Originally Posted by lowmaster
I have a textfile with a list of strings I want to monitor in my network.

alertlist:
Code:
hans
franz
tanz

So it can output for me whenever the a strings it matched:
Code:
#!/bin/sh
while : ; do
    testfile="/var/media/ftp/alertlist.txt"
  [[ -f "$testfile" ]] && echo "${testfile##*/} exists." ||  echo "${testfile##*/} does not exist."
  while /var/media/ftp/look.sh active | grep -i -f  /var/media/ftp/alertlist.txt
  do
???
        sleep 4 
    done
    sleep 4
done&

Now what I want is eh a notification, whenever the state changes, example, hans joins, franz leaves franz and tanz joins etc.

not when found or nor, only when the situation changes

how can I do this while keepin the I/O to the flashdrives to a minimum?
If you want to keep I/O to a flashdrive to a minimum, why are you accessing that flashdrive at least four times every 4 seconds?

If you have a list of strings to search for, why do you have to test every four seconds whether or not your list exists? Does this list change frequently while you're running your script?

If you have a program you want to run every 4 seconds and you want to minimize accesses to a flashdrive, why is the program you want to run on a flashdrive?

What does /var/media/ftp/look.sh do? Does it invoke any other software that is located on that flashdrive? Does it access any other files that are located on that flashdrive?

Why are any of these files on a flashdrive if you don't want to access the flashdrive?

What output does /var/media/ftp/look.sh produce? Is the output just strings exactly matching the format of the strings in /var/media/ftp/alertlist.txt, or do lines in the output contain additional text that needs to be stripped away as part of your output?

Can a string in /var/media/ftp/alertlist.txt appear in the output from /var/media/ftp/look.sh more than once? If so, does the output from your script need to notice differences in the number of times a string is found? Or, does it just need to notice when the number of times a given string string appears changes from zero to non-zero and from non-zero to zero?

Does you output just need to give a list of the strings that changed status? Or does the output need to report strings that appeared and strings that disappeared, or the number of times a string appeared in the latest time through the loop?

If these strings are people's names or login IDs, do you really need case insensitive matches? Are UserName and username to be treated as different strings or as a single string?
# 6  
Old 04-22-2016
Quote:
Originally Posted by Don Cragun
If you want to keep I/O to a flashdrive to a minimum, why are you accessing that flashdrive at least four times every 4 seconds?
Thats a good point! I need to fix this. 8-)

Quote:
If you have a list of strings to search for, why do you have to test every four seconds whether or not your list exists?
The list changes, but reading it once every hour should be sufficient

If you have a program you want to run every 4 seconds and you want to minimize accesses to a flashdrive, why is the program you want to run on a flashdrive?

Quote:
What does /var/media/ftp/look.sh do? Does it invoke any other software that is located on that flashdrive? Does it access any other files that are located on that flashdrive?
Look.sh calls a system internal function which goes through a set of arrays with which you can output several information. in this case I just let output clients in the network and its state (active/online)

Quote:
Why are any of these files on a flashdrive if you don't want to access the flashdrive?
it is how it is...

Quote:
What output does /var/media/ftp/look.sh produce?
lines in the output like in the alertlist.txt

Quote:
Can a string in /var/media/ftp/alertlist.txt appear in the output from /var/media/ftp/look.sh more than once?
If you mean as a part of a string yes. so if alertlist.txt contains hans, look.sh could output this what I would like to have considered

hans
hansolo
Hansala

Hans joined
Hansala left
Hans left
hansolo joined

etc...

Quote:
If these strings are people's names or login IDs, do you really need case insensitive matches? Are UserName and username to be treated as different strings or as a single string?
ideally yes
# 7  
Old 06-14-2016
I saw there is a watch command available
This should display all output differences? can maybe this be used for this?

can this be used to just consider the data in the lists?

watch - Repeat Linux / Unix Command Regular Intervals
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Email alert after termination

I am running the gaussian program on UNIX with bash and I want to form a script that will email me once the output life terminates either "normal termination" or "false" I just started learning this last week so could you let me know how to go about this.:b: (13 Replies)
Discussion started by: Jade_Michael
13 Replies

2. UNIX for Beginners Questions & Answers

Email Alert in UNIX

Hi There I have to wrote a script where I am able to echo a result of an SQL script, however I want to be able to send an email to myself when it is more than 0 (so whenever a value is returned) is this possible? I tried one way from looking on the web but this didn't work, I have added my... (8 Replies)
Discussion started by: simpsa27
8 Replies

3. Shell Programming and Scripting

Using top command to email if process is exceeding 25% and sending an email alert if so

This is my first time writing a script and Im having some trouble, Im trying to use the top command to monitor processes and the amount of CPU usage they require, my aim is to get an email if a process takes over a certain percentage of CPU usage I tried grep Obviosly that hasnt worked, Any... (8 Replies)
Discussion started by: jay02
8 Replies

4. UNIX for Dummies Questions & Answers

new to ldap, send email to a ou or group, and see a list from email client

hi, i'm running openldap on ubuntu 10.04, creating new items with apache directory studio (windows version). i use the ldap just as an address book to our small office (email clients are windows live mail 2009, 2011, microsoft outlook 2007 and 2010). a. i cant see a list of the contacts,... (0 Replies)
Discussion started by: V4705
0 Replies

5. Shell Programming and Scripting

email Alert

Hello, I want a script that will scan the file /etc/httpd/conf/httpd.conf and the folder /etc/httpd/libexec/ -bash-2.05b# grep mod_r /etc/httpd/conf/httpd.conf LoadModule rewrite_module libexec/mod_rewrite.so AddModule mod_rewrite.c -bash-2.05b# -bash-2.05b# find... (4 Replies)
Discussion started by: fed.linuxgossip
4 Replies

6. IP Networking

Squid and email client

Hi All, We plan to use squid has a proxy so my question is if I use squid then is this support email clients like outlook express or microsoft outlook at client side and is any option in the squid to block few of the unwanted URL's Thanks, Bachegowda (7 Replies)
Discussion started by: bache_gowda
7 Replies

7. Programming

HELP broadcasting client IDs to network in C

I am trying to write a client server chat program in C and am unsure as to how I would broadcast all the users IDs over the network. At the moment I have the usernames stored in a array clientsock.cl_id, I am able to output this information to the server but am unsure how to transmit this... (1 Reply)
Discussion started by: dooker
1 Replies

8. Shell Programming and Scripting

Email alert script

I need to code a script, which will run via cron, every 30 minutes. The script will read a file containing a date&time and number (which represents disk space). The file gets appended to every 30 minutes. Here's a sample of the file: CPU 1:04/25/02 1:00 am:1972554 CPU 1:04/25/02 1:30... (1 Reply)
Discussion started by: moon
1 Replies
Login or Register to Ask a Question