LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-25-2008, 10:09 AM   #1
trolojik1
LQ Newbie
 
Registered: May 2008
Posts: 4

Rep: Reputation: 0
Create a bash file


Hi i want a bash file like that

#!/bin/bash
A=`netstat -an | grep ":80 "| awk '{print $5}'|cut -d":" -f1 | sort |uniq -c |sort -nr |$
for i in $A; do
if [ $i -gt 20 ]; then
echo higher value block that!!
echo item: $i
fi
done


if value is higher than 20 i want to block that ip adress

Can you help me ?

Regards;
 
Old 05-25-2008, 12:28 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Are you saying you want to create the file?

If so you can just decide the name of the file then type:
vi <filename>

This puts you in the vi (or vim) editor which has tons of options. You can type "man vi" before doing it to get an idea of all its capabilities.

Once in vi just insert the text you're interested in then save the file.

You have to change mode (permissions) on the file with the chmod command to make it executable. Type "man chmod" for details.

You then have to insure the directory is in your PATH variable OR remember to invoke it with fully qualified path. For example if the file is in your home directory (/home/mydir) you'd need to add /home/mydir to PATH if not already there or always type /home/mydir/<filename> whenever you want to access it.

This by the way is called a "shell script". It is similar (but more powerful) to DOS batch files. Most people but a .sh suffix on such files but Linux/UNIX doesn't require a suffix. You could name it bill.bob if you wanted to do so.
 
Old 05-25-2008, 01:10 PM   #3
trolojik1
LQ Newbie
 
Registered: May 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Hi buddy, please read becarefully
I dont have a problem with creating file. I Have a problem with coding. I Don't know how to coding what i want.

I Want : netstat -an | grep ":80 "| awk '{print $5}'|cut -d":" -f1 | sort |uniq -c |sort nr <-- do this command every 20 seccond by automaticly and if result is higher than 20 , i want block that ip adresses.

I Need help.

Regards
 
Old 05-25-2008, 01:37 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
please read becarefully


From your original post I submit the title:

Quote:
Create a bash file


It seemed you had already coded what you wanted and just didn't know how to "create" the file.

Maybe in your next attempt you'll be more exact or at least learn not to annoy someone who tried to answer you. Maybe you'll even learn to edit what you write and not use the nonexistent word "becarefully".
 
Old 05-25-2008, 03:03 PM   #5
trolojik1
LQ Newbie
 
Registered: May 2008
Posts: 4

Original Poster
Rep: Reputation: 0
you right, my mistake;
I appoligise
 
Old 05-25-2008, 07:31 PM   #6
trolojik1
LQ Newbie
 
Registered: May 2008
Posts: 4

Original Poster
Rep: Reputation: 0
can help anyone ?

i want a create bash file which contains that what i described
 
Old 05-26-2008, 02:48 AM   #7
angrybanana
Member
 
Registered: Oct 2003
Distribution: Archlinux
Posts: 147

Rep: Reputation: 21
Change `echo "$ip"` with whatever command it is you use to block ip addresses.
Code:
while sleep 20;do
  while read ip;do
    echo "$ip"
  done < <(netstat -an|awk '/:80 /&&split($5,a,":"){ count[a[1]]++ } END{ for (x in count){ if (count[x]>20){ print x }}}')
done
 
  


Reply

Tags
bash, file



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i create an empty bash(.sh) file in command line? bbmak Linux - Newbie 1 10-26-2007 02:39 AM
Bash script to read file and alter lines depending on create date ChristianHein Linux - General 13 08-04-2007 05:39 AM
create variable name in bash kilgor Programming 3 12-31-2005 10:50 AM
Create a text file using Bash Boffy Programming 5 03-14-2005 09:06 PM
howto create a file based on date in bash rohan208 Linux - Newbie 2 05-07-2004 03:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration