ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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".
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.