Sponsored Content
Top Forums Shell Programming and Scripting Write only changes to file - avoid duplicates Post 303028015 by aristosv on Saturday 29th of December 2018 06:00:32 PM
Old 12-29-2018
Actually instead of exporting the banned IP addresses every 60 seconds and writing them to a file, I ended up reading fail2ban log files to find which IP's were banned.

Code:
cat /var/log/fail2ban.log* | grep -o 'Ban.*' | sed 's/\<Ban\> //g' | sort -u

The actual issue that I am trying to solve, is that the current version of FreePBX can only run fail2ban v0.8.14, which does not maintain it's list of banned IP addresses after a reboot. So I wanted to somehow save the list of banned IP's, and after reboot, manually ban them again. Something like this:

Code:
for ip in $(cat /var/log/fail2ban.log* | grep -o 'Ban.*' | sed 's/\<Ban\> //g' | sort -u); do fail2ban-client set asterisk-iptables banip $ip; done

Which again is not really working 100%, so now I'm thinking of using iptables commands to ban the IP's, not fail2ban commands.

But I appreciate your suggestions and the discussion. It helps with the learning.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Avoid Duplicates in a file

Hi Gurus, I had a question regarding avoiding duplicates.i have a file abc.txt abc.txt ------- READER_1_1_1> HIER_28056 XML Reader: Error occurred while parsing:; line number ; column number READER_1_3_1> Sun Mar 23 23:52:48 2008 READER_1_3_1> HIER_28056 XML Reader: Error occurred while... (7 Replies)
Discussion started by: pssandeep
7 Replies

2. Shell Programming and Scripting

How to avoid a temp file

Hi all. I want to check the free space on a given FS and process the output. Right now, I'm using a temp file to avoid using df twice. This is what I'm doing #!/usr/bin/ksh ... df -k $FS_NAME > $TMP_FILE 2>&1 if ]; then RESULT="CRITICAL - $(cat $TMP_FILE)" else cat $TMP_FILE | ...... (3 Replies)
Discussion started by: fox1212
3 Replies

3. HP-UX

Parameter to avoid file being deleted by SAM

Good afternoon. I am a newbie. We just had a potentially big problem (negated to having good backups). Basically, there is an option in SAM, to delete all the data from the system that a user ever created. Lo and behold, silly me, I choose that option, and all sorts of needed files... (5 Replies)
Discussion started by: instant000
5 Replies

4. Shell Programming and Scripting

Avoid file creation in a script...achive same result

Guys following lines help me in getting numbers from PID column ,to be thrown into first column of a CSV file. COLUMNS=2047 /usr/bin/ps -eo pid,ppid,uid,user,args | grep -v "PID" > /tmp/masterPID.txt cat /tmp/masterPID.txt|while read line do PID=`echo $line|awk '{print $1}'` echo "$PID"... (4 Replies)
Discussion started by: ak835
4 Replies

5. Shell Programming and Scripting

avoid open file to check field.

Hi Everyone, # cat a.txt 94,aqqc,62345907, 5,aeec,77, # cat 1.pl #!/usr/bin/perl use strict; use warnings; use Date::Manip; open(my $FA, "/root/a.txt") or die "$!"; while(<$FA>) { chomp; my @tmp=split(/\,/, $_); if (index($tmp, "qq") ne -1) { ... (4 Replies)
Discussion started by: jimmy_y
4 Replies

6. Programming

[c]Why first file is creating after the second. How to avoid

Hi, My Code is as below: nbECRITS = fwrite(strstr(data->buffer, ";") + 1, sizeof(char), (data->buffsize) - LEN_NOM_FIC, fic_sortie); fclose(fic_sortie); sprintf(PATH_BALISE, "%s.balise", PATH); fic_balise_data = fopen(PATH_BALISE, "a+"); if (fic_balise_data == NULL) {... (1 Reply)
Discussion started by: ezee
1 Replies

7. Shell Programming and Scripting

Request to check remove duplicates but write before it

Hi alll I have a file with following kind input I want in output duplicates should not be there but there should be numbering mentioned before that like (4 Replies)
Discussion started by: manigrover
4 Replies

8. Shell Programming and Scripting

Request to check:remove duplicates and write sytematically

Hi all I have a file with following input It contains 5 columns gene name drug drug ID disease approved Now the same gene is repeated many times with different data in column2,3 ,4,5 I want to arrange dat in such a way that there shuld be one entry in the column(no... (2 Replies)
Discussion started by: manigrover
2 Replies

9. Shell Programming and Scripting

How to avoid ssh :Write failed: Broken pipe?

Hello, I am trying to run some code on Matlab over ssh . The code takes around 5-6 hours to complete. so after giving the command to run it , I locked my machine and then went off to sleep at night, only to discover in the morning that I get this message : ...Code running, partial results... (1 Reply)
Discussion started by: ajayram
1 Replies

10. Shell Programming and Scripting

Avoid overwriting backup file when multiple entries need to replace in one file input from another

Hello, I have been working on script in which search and replace the multiple pattern. 1. update_params.sh read the multiple pattern from input file ParamMapping.txt(old_entry|New_entry) and passing this values one by one to change_text.sh 2. change_text.sh read... (0 Replies)
Discussion started by: ketanraut
0 Replies
LBDB-FETCHADDR(1)						   User Manuals 						 LBDB-FETCHADDR(1)

NAME
lbdb-fetchaddr - grab addresses from mails add append them to lbdb database SYNOPSIS
lbdb-fetchaddr [-d dateformat] [-x headerfieldlist] [-c charset] [-a] lbdb-fetchaddr [-v|-h] DESCRIPTION
lbdb-fetchaddr is a shell script which reads a mail on stdin. It extracts the contents of some header fields (default: `From:', `To:', `Cc:', `Resent-From:', and `Resent-To:') from the mail header (only addresses with a real name) and appends them to $HOME/.lbdb/m_inmail.list. For performance issues lbdb-fetchaddr appends new addresses to this file without removing duplicates. To get rid of duplicates, the program lbdb-munge exists, which is run by m_inmail if needed and removes duplicates. To use this program, put the following lines into your $HOME/.procmailrc: :0hc | lbdb-fetchaddr lbdb-fetchaddr writes the actual date to the third column of the database by using strftime(3). It uses "%Y-%m-%d %H:%M" as the default date format (e.g. "1999-04-29 14:33"). You can change this by using the -d option to select a different date format string as parameter of lbdb-fetchaddr command like :0hc | lbdb-fetchaddr -d "%y-%m-%d" which results in e.g. "99-04-29". OPTIONS
-v Print version number of lbdb-fetchaddr. -h Print short help of lbdb-fetchaddr. -d dateformat Use the given date format using strftime(3) syntax. -x headerfields A colon separated list of header fields, which should be searched for mail addresses. If this option isn't given, we fall back to `from:to:cc:resent-from:resent-to'. -c charset The charset which will be used to write the database. This should be the charset which the application expects (normally the one from your current locale). If this option isn't given, we fall back to `iso-8859-15'. -a Also grab addresses without a real name. Use the local part of the mail address as real name. FILES
$HOME/.lbdb/m_inmail.list /usr/lib/lbdb/fetchaddr /usr/lib/lbdb/m_inmail SEE ALSO
lbdbq(1), lbdb_dotlock(1), procmail(1), procmailrc(5), strftime(3). CREDITS
Most of the really interesting code of this program (namely, the RFC 822 address parser used by lbdb-fetchaddr) was stolen from Michael Elkins' mutt mail user agent. Additional credits go to Brandon Long for putting the query functionality into mutt. AUTHOR
The lbdb package was written by Thomas Roessler <roessler@guug.de> and is now maintained and extended by Roland Rosenfeld <roland@spin- naker.de>. Unix October 2005 LBDB-FETCHADDR(1)
All times are GMT -4. The time now is 01:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy