* Need Help with making a bash script
@ 2004-05-28 21:36 Fernando
2004-05-28 22:40 ` Jens Knoell
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Fernando @ 2004-05-28 21:36 UTC (permalink / raw)
To: linux-admin
I have two problems.
1. I'm making a script to add IP's to my blacklist...
I need to add three <tabs>, the word 'REJECT' and a #DDMMYYYY that it's
being done to a text file that has the IP's in it... ie this is the
original list;
80.25.148.216
80.43.197.197
needs to end up like this...
80.25.148.216 REJECT #28052004
80.43.197.197 REJECT #28052004
2. The second is a little bit more complicated.
My server is having trouble deleting virus emails, I want to help it
along with a little cron job that will clear out virus emails every 10
minutes or so. I get the list of infected emails from the maillog but in
the maillog only the email ID is displayed. In the actual queue there
are two files per 1 email ID.
ie... this is what the log spits out as emails that are infected that I
want to delete...
foo1
foo2
foo3
but in the queue there are two files per email, a qffoo and a dffoo so
in the queue the previous emails would actually be...
dffoo1
qffoo1
dffoo2
qffoo2
dffoo3
qffoo3
So, is it possible to run rm with a wildcard to compensate for the df qf
letters and still feed it the list of email ID's which make up the last
part of the df qf files?
don't have a clue where to start, thanks
Fernando
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Need Help with making a bash script
2004-05-28 21:36 Need Help with making a bash script Fernando
@ 2004-05-28 22:40 ` Jens Knoell
2004-05-28 22:43 ` Herta Van den Eynde
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Jens Knoell @ 2004-05-28 22:40 UTC (permalink / raw)
To: Fernando; +Cc: linux-admin
Hi Fernando
answers inline.
Fernando wrote:
> I have two problems.
>
>
> 1. I'm making a script to add IP's to my blacklist...
>
> I need to add three <tabs>, the word 'REJECT' and a #DDMMYYYY that it's
> being done to a text file that has the IP's in it... ie this is the
> original list;
>
> 80.25.148.216
> 80.43.197.197
>
> needs to end up like this...
>
> 80.25.148.216 REJECT #28052004
> 80.43.197.197 REJECT #28052004
I just happen to have almost exactly such a script running here. The
relevant part is this one here, modified to your needs. It requires that
you set SOURCEFILE to whatever file you use. Same for DESTFILE. I didn't
put any secure checks for either source or dest in there, just FYI.
rm $DESTFILE
cat $SOURCEFILE | while read TCPREMOTEIP
do
echo "$TCPREMOTEIP<insert TABs here>REJECT #`date +%Y%m%d`" >> $DESTFILE
done
The same thing can probably also be done faster with sed.
> 2. The second is a little bit more complicated.
>
> My server is having trouble deleting virus emails, I want to help it
> along with a little cron job that will clear out virus emails every 10
> minutes or so. I get the list of infected emails from the maillog but in
> the maillog only the email ID is displayed. In the actual queue there
> are two files per 1 email ID.
>
> ie... this is what the log spits out as emails that are infected that I
> want to delete...
>
> foo1
> foo2
> foo3
>
> but in the queue there are two files per email, a qffoo and a dffoo so
> in the queue the previous emails would actually be...
>
> dffoo1
> qffoo1
> dffoo2
> qffoo2
> dffoo3
> qffoo3
>
> So, is it possible to run rm with a wildcard to compensate for the df qf
> letters and still feed it the list of email ID's which make up the last
> part of the df qf files?
Yes, simply run it with wildcards like this: rm ??foo1
Hope this helps
Jen
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Need Help with making a bash script
2004-05-28 21:36 Need Help with making a bash script Fernando
2004-05-28 22:40 ` Jens Knoell
@ 2004-05-28 22:43 ` Herta Van den Eynde
2004-05-29 5:04 ` Fernando
2004-05-28 23:52 ` chuck gelm
` (3 subsequent siblings)
5 siblings, 1 reply; 9+ messages in thread
From: Herta Van den Eynde @ 2004-05-28 22:43 UTC (permalink / raw)
To: linux-admin
[-- Attachment #1: Type: text/plain, Size: 1953 bytes --]
ip.bsh expects a file with ip addresses named ip.in in the same directory.
It will produce ip.out. Don't cut-n-paste the script as you'll probably
lose the tabs (they've been entered with <Ctrl/V>+<Tab> in vi, in case you
wondered).
email.bsh expects a file email.in with the IDs, and produces email.out.
Kind regards,
Herta
Quoting Fernando <ferosspublic@comcast.net>:
> I have two problems.
>
>
> 1. I'm making a script to add IP's to my blacklist...
>
> I need to add three <tabs>, the word 'REJECT' and a #DDMMYYYY that it's
> being done to a text file that has the IP's in it... ie this is the
> original list;
>
> 80.25.148.216
> 80.43.197.197
>
> needs to end up like this...
>
> 80.25.148.216 REJECT #28052004
> 80.43.197.197 REJECT #28052004
>
>
>
> 2. The second is a little bit more complicated.
>
> My server is having trouble deleting virus emails, I want to help it
> along with a little cron job that will clear out virus emails every 10
> minutes or so. I get the list of infected emails from the maillog but in
>
> the maillog only the email ID is displayed. In the actual queue there
> are two files per 1 email ID.
>
> ie... this is what the log spits out as emails that are infected that I
> want to delete...
>
> foo1
> foo2
> foo3
>
> but in the queue there are two files per email, a qffoo and a dffoo so
> in the queue the previous emails would actually be...
>
> dffoo1
> qffoo1
> dffoo2
> qffoo2
> dffoo3
> qffoo3
>
> So, is it possible to run rm with a wildcard to compensate for the df qf
>
> letters and still feed it the list of email ID's which make up the last
> part of the df qf files?
>
>
> don't have a clue where to start, thanks
>
> Fernando
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin"
> in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
[-- Attachment #2: ip.bsh --]
[-- Type: application/octet-stream, Size: 69 bytes --]
#!/bin/bash
sed -e "s:$: REJECT \#`date +%d%m%Y`:" ip.in > ip.out
[-- Attachment #3: email.bsh --]
[-- Type: application/octet-stream, Size: 63 bytes --]
#!/bin/bash
sed -e "s:.*:rm df&; rm qf&:" email.in > email.out
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Need Help with making a bash script
2004-05-28 21:36 Need Help with making a bash script Fernando
2004-05-28 22:40 ` Jens Knoell
2004-05-28 22:43 ` Herta Van den Eynde
@ 2004-05-28 23:52 ` chuck gelm
2004-05-29 0:05 ` chuck gelm
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: chuck gelm @ 2004-05-28 23:52 UTC (permalink / raw)
To: Fernando; +Cc: linux-admin
Fernando wrote:
> I have two problems.
>
>
> 1. I'm making a script to add IP's to my blacklist...
>
> I need to add three <tabs>, the word 'REJECT' and a #DDMMYYYY that it's
> being done to a text file that has the IP's in it... ie this is the
> original list;
>
> 80.25.148.216
> 80.43.197.197
>
> needs to end up like this...
>
> 80.25.148.216 REJECT #28052004
> 80.43.197.197 REJECT #28052004
>
>
>
> 2. The second is a little bit more complicated.
>
> My server is having trouble deleting virus emails, I want to help it
> along with a little cron job that will clear out virus emails every 10
> minutes or so. I get the list of infected emails from the maillog but in
> the maillog only the email ID is displayed. In the actual queue there
> are two files per 1 email ID.
>
> ie... this is what the log spits out as emails that are infected that I
> want to delete...
>
> foo1
> foo2
> foo3
>
> but in the queue there are two files per email, a qffoo and a dffoo so
> in the queue the previous emails would actually be...
>
> dffoo1
> qffoo1
> dffoo2
> qffoo2
> dffoo3
> qffoo3
>
> So, is it possible to run rm with a wildcard to compensate for the df qf
> letters and still feed it the list of email ID's which make up the last
> part of the df qf files?
>
>
> don't have a clue where to start, thanks
>
> Fernando
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
example usage:
sh test.sh < infilename > outfilename
# test.sh
ADDON="\tREJECT\t#28052004\n"
BUFFER="\n"
while [ $BUFFER != $ADDON ]; do
read GOZINDA
BUFFER="$GOZINDA$ADDON"
printf $BUFFER
done
# test.sh
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Need Help with making a bash script
2004-05-28 21:36 Need Help with making a bash script Fernando
` (2 preceding siblings ...)
2004-05-28 23:52 ` chuck gelm
@ 2004-05-29 0:05 ` chuck gelm
2004-05-29 0:59 ` A. R. Vener
2004-05-29 20:00 ` Russell Evans
5 siblings, 0 replies; 9+ messages in thread
From: chuck gelm @ 2004-05-29 0:05 UTC (permalink / raw)
To: Fernando; +Cc: linux-admin
Fernando wrote:
> I have two problems.
>
>
> 1. I'm making a script to add IP's to my blacklist...
>
> I need to add three <tabs>, the word 'REJECT' and a #DDMMYYYY that it's
> being done to a text file that has the IP's in it... ie this is the
> original list;
>
> 80.25.148.216
> 80.43.197.197
>
> needs to end up like this...
>
> 80.25.148.216 REJECT #28052004
> 80.43.197.197 REJECT #28052004
>
>
>
> 2. The second is a little bit more complicated.
>
> My server is having trouble deleting virus emails, I want to help it
> along with a little cron job that will clear out virus emails every 10
> minutes or so. I get the list of infected emails from the maillog but in
> the maillog only the email ID is displayed. In the actual queue there
> are two files per 1 email ID.
>
> ie... this is what the log spits out as emails that are infected that I
> want to delete...
>
> foo1
> foo2
> foo3
>
> but in the queue there are two files per email, a qffoo and a dffoo so
> in the queue the previous emails would actually be...
>
> dffoo1
> qffoo1
> dffoo2
> qffoo2
> dffoo3
> qffoo3
>
> So, is it possible to run rm with a wildcard to compensate for the df qf
> letters and still feed it the list of email ID's which make up the last
> part of the df qf files?
>
>
> don't have a clue where to start, thanks
>
> Fernando
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
part 2:
example:
sh test.sh < infilename
#test.sh
GOZINDA="text"
while [ $GOZINDA != "" ]; do
read GOZINDA
printf "rm df$GOZINDA\n"
# rm df$GOZINDA
printf "rm qf$GOZINDA\n"
# rm qf$GOZINDA
printf "\n"
done
#test.sh
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Need Help with making a bash script
2004-05-28 21:36 Need Help with making a bash script Fernando
` (3 preceding siblings ...)
2004-05-29 0:05 ` chuck gelm
@ 2004-05-29 0:59 ` A. R. Vener
2004-05-29 20:00 ` Russell Evans
5 siblings, 0 replies; 9+ messages in thread
From: A. R. Vener @ 2004-05-29 0:59 UTC (permalink / raw)
To: linux-admin
For your first problem:
today=`date "#+%d%m%Y"`
while read ipaddr
do
echo "$ipaddr REJECT $today"
done < blacklist_file > /tmp/new_file$$
mv /tmp/new_file$$ blacklist_file
On Fri, May 28, 2004 at 05:36:49PM -0400, Fernando wrote:
> I have two problems.
>
>
> 1. I'm making a script to add IP's to my blacklist...
>
> I need to add three <tabs>, the word 'REJECT' and a #DDMMYYYY that it's
> being done to a text file that has the IP's in it... ie this is the
> original list;
>
> 80.25.148.216
> 80.43.197.197
>
> needs to end up like this...
>
> 80.25.148.216 REJECT #28052004
> 80.43.197.197 REJECT #28052004
>
>
>
> 2. The second is a little bit more complicated.
--
Rudy Vener
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Need Help with making a bash script
2004-05-28 22:43 ` Herta Van den Eynde
@ 2004-05-29 5:04 ` Fernando
0 siblings, 0 replies; 9+ messages in thread
From: Fernando @ 2004-05-29 5:04 UTC (permalink / raw)
To: linux-admin
Hey I apreciate all of the answers but these scripts are nice and
simple. They get the job done in one line with sed.
thanks again.
Herta Van den Eynde wrote:
> ip.bsh expects a file with ip addresses named ip.in in the same directory.
> It will produce ip.out. Don't cut-n-paste the script as you'll probably
> lose the tabs (they've been entered with <Ctrl/V>+<Tab> in vi, in case you
> wondered).
>
> email.bsh expects a file email.in with the IDs, and produces email.out.
>
> Kind regards,
>
> Herta
>
> Quoting Fernando <ferosspublic@comcast.net>:
>
>
>>I have two problems.
>>
>>
>>1. I'm making a script to add IP's to my blacklist...
>>
>>I need to add three <tabs>, the word 'REJECT' and a #DDMMYYYY that it's
>>being done to a text file that has the IP's in it... ie this is the
>>original list;
>>
>>80.25.148.216
>>80.43.197.197
>>
>>needs to end up like this...
>>
>>80.25.148.216 REJECT #28052004
>>80.43.197.197 REJECT #28052004
>>
>>
>>
>>2. The second is a little bit more complicated.
>>
>>My server is having trouble deleting virus emails, I want to help it
>>along with a little cron job that will clear out virus emails every 10
>>minutes or so. I get the list of infected emails from the maillog but in
>>
>>the maillog only the email ID is displayed. In the actual queue there
>>are two files per 1 email ID.
>>
>>ie... this is what the log spits out as emails that are infected that I
>>want to delete...
>>
>>foo1
>>foo2
>>foo3
>>
>>but in the queue there are two files per email, a qffoo and a dffoo so
>>in the queue the previous emails would actually be...
>>
>>dffoo1
>>qffoo1
>>dffoo2
>>qffoo2
>>dffoo3
>>qffoo3
>>
>>So, is it possible to run rm with a wildcard to compensate for the df qf
>>
>>letters and still feed it the list of email ID's which make up the last
>>part of the df qf files?
>>
>>
>>don't have a clue where to start, thanks
>>
>>Fernando
>>
>>-
>>To unsubscribe from this list: send the line "unsubscribe linux-admin"
>>in
>>the body of a message to majordomo@vger.kernel.org
>>More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Need Help with making a bash script
2004-05-28 21:36 Need Help with making a bash script Fernando
` (4 preceding siblings ...)
2004-05-29 0:59 ` A. R. Vener
@ 2004-05-29 20:00 ` Russell Evans
2004-06-01 13:03 ` Fernando
5 siblings, 1 reply; 9+ messages in thread
From: Russell Evans @ 2004-05-29 20:00 UTC (permalink / raw)
To: linux-admin
On Fri, 28 May 2004 17:36:49 -0400
"Fernando" <ferosspublic@comcast.net> wrote:
> I have two problems.
>
>
> 1. I'm making a script to add IP's to my blacklist...
>
> I need to add three <tabs>, the word 'REJECT' and a #DDMMYYYY that
> it's being done to a text file that has the IP's in it... ie this is
> the original list;
>
> 80.25.148.216
> 80.43.197.197
>
> needs to end up like this...
>
> 80.25.148.216 REJECT #28052004
> 80.43.197.197 REJECT #28052004
>
Assuming that you are documenting why you are blocking an address,
instead of the date as a comment, you might was to use a case number.
The case number would point to a record of the event that triggered the
blocking, with the appropriate log files snips, packet traces, machines
effected, ...
Thank you
Russell
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Need Help with making a bash script
2004-05-29 20:00 ` Russell Evans
@ 2004-06-01 13:03 ` Fernando
0 siblings, 0 replies; 9+ messages in thread
From: Fernando @ 2004-06-01 13:03 UTC (permalink / raw)
To: linux-admin
Russell Evans wrote:
> On Fri, 28 May 2004 17:36:49 -0400
> "Fernando" <ferosspublic@comcast.net> wrote:
>
>
>>I have two problems.
>>
>>
>>1. I'm making a script to add IP's to my blacklist...
>>
>>I need to add three <tabs>, the word 'REJECT' and a #DDMMYYYY that
>>it's being done to a text file that has the IP's in it... ie this is
>>the original list;
>>
>>80.25.148.216
>>80.43.197.197
>>
>>needs to end up like this...
>>
>>80.25.148.216 REJECT #28052004
>>80.43.197.197 REJECT #28052004
>>
>
>
> Assuming that you are documenting why you are blocking an address,
> instead of the date as a comment, you might was to use a case number.
> The case number would point to a record of the event that triggered the
> blocking, with the appropriate log files snips, packet traces, machines
> effected, ...
>
> Thank you
> Russell
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
I was thinking about putting the date in because I was going to clear
out IP's after a couple of months. Just in case it was a one time error
where they sent out infected email. The case number system sounds
interesting, would I need it for CYA for anything?
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2004-06-01 13:03 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-28 21:36 Need Help with making a bash script Fernando
2004-05-28 22:40 ` Jens Knoell
2004-05-28 22:43 ` Herta Van den Eynde
2004-05-29 5:04 ` Fernando
2004-05-28 23:52 ` chuck gelm
2004-05-29 0:05 ` chuck gelm
2004-05-29 0:59 ` A. R. Vener
2004-05-29 20:00 ` Russell Evans
2004-06-01 13:03 ` Fernando
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).