Unable to run my logic here, can someone please help?
Hi Folks,
Here I want to present STDINput to the user so that they can enter the IP addresses.
Here is my script but dang that one is not working Code:
#!/bin/bash
Can someone please help me on this issue; pls? |
Quote:
Past that, this doesn't seem to make much sense at all from a usability standpoint. You've been asking about scripts for YEARS now, and know how to get input from a user at the command line. Do you honestly think that a user is going to enter 1,000 IP addresses...BY HAND....ONE AT A TIME...into a script? Would be far better to read an input file containing those addreses, and do what you'd like with each one. And why a limit of 1,000? If all you're doing is making directories based on a list, then a very simple loop to just run mkdir is all you need...if the directory exists, it won't create another with the same name, and if not, it creates it. Simple. To address your questions:
|
If you want to 'catch' (or trap) things like control-c:
Use a trap |
TB0one -
Someone is posting their doubts that means he or she must have already thought about this. Not necessarily 1000 IP addresses need to be entered at once; not necessarily end-user is versed with VIM or nano or Linux to enter the IP address in the file and save. Cumulatively they should not exceed more than 1000 since my device buffer does not allow more than 1000 IPs. And about my second doubt, I posted my script is even if more than 1000 entries are added in pre-customBL all are being added in customBL. I want as soon as 1000 limit is exceeded in the pre-customBL script should throw alert and should not allow adding further. |
Do it as a loop then that terminates at 1000 entries no matter what, on top of any other termination events.
P.S.: Since you're reading the IPs from a text file anyway, give your data entry noobs a running instance of nano or vim with line numbers and give them a cheat sheet on how to save the file. In fact, you could bind save in either to 'control s', since you're teaching them about control d and c, anyway. Even better: Put your efforts into writing a solution that takes an input file of any length that chunks it up into batches of thousands. That way you can keep a really long input file, sort and 'uniq' it, and then feed it in thousands to your hardware. |
Quote:
And again, reading a file eliminates the need for ANY buffer, at all. Quote:
Past that, your script does no checking, since I can enter ANYTHING into it...it will accept "1.1.1.1" as well as "John Doe", or "1.65,19". Also, the word "doubt" and the word "question" mean different things. |
Quote:
I also agree with the notion of nobody wanting to input 1000 IP addresses (and yes, after a while the numbers start to dance...), but maybe you actually operate like that, stranger things have happened, but if they are so unskilled that they cannot be taught the usage of simple text editing, well. Don't give them a shell where they can run scripts. Unless you change the system to only allow them that script but that's so much hubbub for...nothing. Anyway, if you want to stick to this, then at least make it as difficult as possible for the person unfortunate enough to do that data entry to mess up, which will happen. Even if you sanitize and verify the structure of the input, etc. There can still be typos. 127.0.0.2 enter AWWWWSHOOT MANAGEERRRRR MAAAANAAAAAGERRRRRRRRRRRRRRRRRRRRRRRRRRRR MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANAAAAAAAAAAAAAGEEEEEEEEEEEEEEEEEEEEERRRR TYPOOOOOOO TYPOOOOOO AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH or more realistically 127.0.0.2 enter ... pfff whatever 127.127.127.127 enter |
Quote:
I would take a look at the 'script(1)' command and use it to collect a terminal session of your script actually being used. Set the maximum number of IP addresses to some small number, say, "5" if you're expecting a human being to do the data entry and try: Code:
$ script myscript.session Q: will the documentation let the user know that the file "/opt/.custombl/customBL" is being created for them and could be used to feed back into your script after they've edited it for errors and length? Personally, I'd have them use some other means -- scraping them out of a log file, querying a database, etc. -- and stashing them in a file of their choosing and then have the user pass that filespec to the script. You can still do the limit checking (that you're already doing) but you're not making the user potentially repeat a lot of keyboard entry should they enter more lines than you want to handle. Your script looks like it's close to doing something like that already---all it needs is to modify where the input's coming from. Like a command line argument: "myscript ip_address.lis" |
Quote:
|
Quote:
I do not understand: cat >> stdin, probably would be nice to explain better |
All times are GMT -5. The time now is 10:20 PM. |