A few arguments to one "key"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A few arguments to one "key"
# 1  
Old 04-06-2008
A few arguments to one "key"

Hi!
I need to pass a few (as much as possible) arguments to one "key", i.e.

./myscript.sh -i one -b 1.1.1.1 2.2.2.2 3.3.3.3 ... -u users

I need to supply one or many IP adresses as a parameters.. I've search in getopts capabilities, but didn't find something for me. One of possibilities I thought - is to quote all list of IP addresses and consider it one argument. But it need more user involving, and I don't want it. Maye some "while" loop can help here?
Thanks for advance

P.S.
Another question (in order not multiply threads). How can I show in web page running output of shell script? Perl/PHP tools? If you have links - please.
# 2  
Old 04-06-2008
If the IP addresses are required, don't make them options (that would indicate they are optional, anyway). In other words, any non-option arguments are IP addresses.

I cannot come up with an alternative which is unambiguous if you don't want the user to quote the list of IP addresses. (You can avoid quoting by using a separator which is not whitespace, of course. Maybe separating the IP addresses with a colon would be acceptable.)

Threads are not a limited resource, and it's actually better to post different questions in different threads. Your question is not very specific, but if this is a CGI script, anything it prints will be visible in the web browser (provided it adheres to some minimal formatting standards). Read the CGI spec, it's really quite simple.

If it's not CGI, perhaps you just want to redirect the output to a text file which is in the document tree of your web server.

Code:
command >~/public_html/output.txt

... would make the output available at http://server/~you/output.txt depending of course on how your web server is configured (and the file probably needs to be chmod a+r).
# 3  
Old 04-06-2008
Thanks, era!
I think it'll be OK, if user separate it by comma. Can you give an example of arguments parsing in this case? Simply to grab all the ip-list to $1 with "case" and then go on it with "foreach"?
Although this can cause another problem with input like "1.1.1.1, 2.2.2.2", where there's whitespace after the comma. But I think there need be some limits for users' input errors and their prevention..If they don't want it working, don't let them touch it.. Smilie)
Thanks for CGI, I'll look at it.
# 4  
Old 04-06-2008
An obscure but fairly common technique is to temporarily tell the shell that the IFS (internal field separator) is the separator you want to use, then just use a particular form of set to perform regular argument splitting into $1, $2, $3, etc.

Code:
OLDIFS=$IFS
IFS=','
set -- $1
IFS=$OLDIFS

for ip in "$@"; do
  echo have $ip
done

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

How to avoid "Too many arguments" error, when passing a long String literal as input to a command?

Hi, I am using awk here. Inside an awk script, I have a variable which contains a very long XML data in string format (500kb). I want to pass this data (as argument) to curl command using system function. But getting Too many arguments error due to length of string data(payloadBlock). I... (4 Replies)
Discussion started by: cool.aquarian
4 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

7. AIX

Ssh installation error "RSA key generation failed"

While trying to upgrade ssh from v4.7 to v5.0 on AIX 5.3 TL9, I end up with the following error. Has anyone come across this? Note: openssl has been upgraded to 0.9.8.840 before this upgrade Bala (0 Replies)
Discussion started by: balaji_prk
0 Replies

8. Solaris

Compliation Error in solaris - macro "min" requires 2 arguments, but only 1 given

Hi, I am trying to compile our linux code base in solaris and came across the following issues. Am I suppose to do something special ? Can anyone help me to fix this issue. System : uname -a SunOS aspen 5.10 Generic_125100-08 sun4u sparc SUNW,Sun-Fire-280R The complier that I am using is... (0 Replies)
Discussion started by: learningkid
0 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question