Sponsored Content
Full Discussion: Using arguments
Top Forums Shell Programming and Scripting Using arguments Post 302569566 by Scrutinizer on Monday 31st of October 2011 06:38:09 PM
Old 10-31-2011
Hi, for starters, you could try something like this:
Code:
#!/bin/sh
# Shell script to pull primary ESA out of a file

FILENAME=/etc/motd   # No space in assignments

if [ $1 -eq 1 ]; then
  if [ "$2" = "GET" ]; then
    # Do work
    extPrimEsa=$(grep "Primary ESA" "$FILENAME"|cut -d\= -f2)
    echo "$extPrimEsa"
  fi
fi

This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Arguments

Ok so i had to create a file and put some random text into it which i did. THen u make a script which takes 2 arguments. The first being a line of text, the second being your newly created file. The script should take the first argument and insert it into the very top (the first line) of... (1 Reply)
Discussion started by: iago
1 Replies

2. Shell Programming and Scripting

[: too many arguments

Hi Guys I have this small Bash script - but it fails when I'm trying to run it. ./test.sh: && ; then # date >> /writable/sys/shutdown.log shutdown -h "now" exit fi done (4 Replies)
Discussion started by: tainted2real
4 Replies

3. Shell Programming and Scripting

Too many arguments?

I can't find anything wrong with this line of code, it works when there is one file in the directory but more than one i get a "too many arguements2 error if ; then am i missing something? (3 Replies)
Discussion started by: Alendrin
3 Replies

4. Shell Programming and Scripting

too many arguments?

i don't know what's wrong with the code, says too many arguments in the first two if statements. how to change it? thx. the file is like in this format: ;dfs;dfdsf;fsd ff dsf;dfdffdfd; -f2 should be only one word with no space, but could be like this 'n/a', '**ABC' while read line; do ... (1 Reply)
Discussion started by: dtdt
1 Replies

5. Shell Programming and Scripting

[: too many arguments

hi I am getting too many arguments error for the below line if ; then Thx in advance (1 Reply)
Discussion started by: vls1210
1 Replies

6. Shell Programming and Scripting

Too many arguments

echo "the number from 1 to 10:" i=1 while do echo $i i=`expr $i+1' done above is the program i written in Linux O.S using vi editor but i am getting the error that while: line 3: i am not understanding that why i am getting this error. can any body please help me regarding this... (3 Replies)
Discussion started by: bsatishbabu
3 Replies

7. Shell Programming and Scripting

grep with two arguments to arguments to surch for

Hello, is it possible to give grep two documents to surche for? like grep "test" /home/one.txt AND /home/two.txt ? thanks (1 Reply)
Discussion started by: Cybertron
1 Replies

8. Shell Programming and Scripting

: [: too many arguments in for -f in if

Hi Experts , I have following code if ; then mv path /filename newdirpath echo "K* files moved successfully to newdirpath \n" else echo "K* files DID NOT moved successfully to newdirpath \n" fi I am getting "echo "K* files DID NOT moved successfully to newdirpath \n"... (19 Replies)
Discussion started by: ajaypatil_am
19 Replies

9. Shell Programming and Scripting

Too many arguments

hi I have this code a="a b c" set -- $a if ; then echo empty fi why is it line 3 reports "test: [: too many arguments"? :wall: Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

10. Ubuntu

[: too many arguments

line 5: #!/bin/bash old=$(du -sh /home/andy/Downloads/myfile.iso) while true; do new=$(du -sh /home/andy/Downloads/myfile.iso) if ; then break fi old=$new xdotool getactivewindow key Ctrl sleep 5 done line 5: bash - Meaning of " (square brackets)... (9 Replies)
Discussion started by: drew77
9 Replies
snmptest(1M)						  System Administration Commands					      snmptest(1M)

NAME
snmptest - communicate with a network entity using SNMP requests SYNOPSIS
/usr/sfw/bin/snmptest [common options] agent DESCRIPTION
snmptest is a flexible SNMP application that can monitor and manage information on a network entity. Invoking snmptest invokes a command line interpreter that accepts commands. This intepreter enables you to send different types of SNMP requests to target agents. The operand agent identifies a target SNMP agent that is instrumented to monitor manageable objects. At its simplest, the agent specifica- tion consists of a host name or an IPv4 address. In this situation, the command attempts communication with the agent, using UDP/IPv4 to port 161 of the target host. See snmpcmd(1M) for a full list of the possible formats for agent. After you invoke snmptest, the command line intepreter prompts with: Variable: At this point you can enter one or more variable names, one per line. A blank line ends the parameter input and sends the request (vari- ables entered) in a single packet to the remote entity. Each variable name is given in the format specified in snmp_variables(4). For exam- ple, the command: snmptest -c public -v 1 zeus Variable: system.sysDescr.0 Variable: ...returns information about the request and reply packets, as well as the data: requestid 0x5992478A errstat 0x0 errindex 0x0 system.sysDescr.0 = STRING: "Unix 4.3BSD" The errstatus value shows the error status code for the call. The possible values for errstat are in the header file /usr/sfw/include/net- snmp/library/snmp.h. The errindex value identifies the variable that has an error. Index values are assigned to all the variables entered at the Variable: prompt. The first value is assigned an index of 1. Upon startup, the program defaults to sending a GET request packet. The type of request can be changed by typing one of the following com- mands at the Variable: prompt: $G Send a GET request. $N Send a GETNEXT request. $S Send a SET request. $B Send a GETBULK request. Note that GETBULK is not available in SNMPv1. $I Send an inform request. $T Send an SNMPv2 trap request. Other values that can be entered at the Variable: prompt are: $D Toggle the dumping of each sent and received packet. $QP Toggle a quicker, less verbose output form. $Q Quit the program. The following are valid request types: GET request When in "GET request" mode ($G or default), you can enter an OID at the Variable: prompt. You can enter multiple OIDs, one per prompt. Enter a blank line to send the GET request. GETNEXT request The "GETNEXT request" mode ($N) is similar to the "GET request" mode, described above. SET request When in the "SET request" mode ($S), more information is requested by the prompt for each variable. The prompt: Type [i|s|x|d|n|o|t|a]: ...requests the type of the variable be entered. Depending on the type of value you want to set, type one of the following: i integer u unsigned integer s octet string in ASCII x octet string in hex bytes, separated by whitespace d octet string as decimal bytes, separated by whitespace a IP address in dotted IP notation o object identifier n null t timeticks At this point a value will be prompted for. To enter an integer value, just type the integer (in decimal). If it is a decimal string, type in whitespace-separated decimal numbers, one per byte of the string. Again, enter a blank line at the prompt for the variable name to send the packet. GETBULK request The "GETBULK request" mode ($B) is similar to the "SET request" mode. Note, however, that GETBULK is not available in SNMPv1. Inform request The "Inform request" mode ($I) is similar to the "SET request" mode. However, this type of request is not available in SNMPv1. Also, the agent specified in the snmptest command should correspond to the target snmptrapd agent. SNMPv2 trap request The "SNMPv2 trap request" mode ($T) is similar to the "SET request" mode. However, this type of request is not available in SNMPv1. Also, the agent specified in the snmptest command should correspond to the target snmptrapd agent. OPTIONS
snmptest takes the common options described in the snmpcmd(1M). EXAMPLES
Example 1: Sending a GET Request for Two OIDs The following is an example of sending a GET request for two OIDs: % snmptest -v 2c -c public testhost:161 Variable: system.sysDescr.0 Variable: system.sysContact.0 Variable: Received Get Response from 128.2.56.220 requestid 0x7D9FCD63 errstat 0x0 errindex 0x0 SNMPv2-MIB::sysDescr.0 = STRING: SunOS testhost 5.9 Generic_112233-02 sun4u SNMPv2-MIB::sysContact.0 = STRING: x1111 Example 2: Sending a GETNEXT Request The following is an example of sending a GETNEXT request: Variable: $N Request type is Getnext Request Variable: SNMPv2-MIB::sysORUpTime.1 Variable: Received Get Response from 128.2.56.220 requestid 0x7D9FCD64 errstat 0x0 errindex 0x0 SNMPv2-MIB::sysORUpTime.2 = Timeticks:(6) 0:00:00.06 Variable: Example 3: Sending a SET Request The following is an example of sending a SET request: Variable: $S Request type is Set Request Variable: system.sysLocation.0 Type [i|u|s|x|d|n|o|t|a]: s Value: building 17 Variable: Received Get Response from 128.2.56.220 requestid 0x7D9FCD65 errstat 0x0 errindex 0x0 SNMPv2-MIB::sysLocation.0 = STRING: building A Variable: Example 4: Sending a GETBULK Request The following is an example of sending a GETBULK request: Variable: $B Request type is Bulk Request Enter a blank line to terminate the list of non-repeaters and to begin the repeating variables Variable: Now input the repeating variables Variable: system.sysContact.0 Variable: system.sysLocation.0 Variable: What repeat count? 2 Received Get Response from 128.2.56.220 requestid 0x2EA7942A errstat 0x0 errindex 0x0 SNMPv2-MIB::sysName.0 = STRING: testhost SNMPv2-MIB::sysORLastChange.0 = Timeticks:(58) 0:00:00.58 SNMPv2-MIB::sysLocation.0 = STRING: bldg A SNMPv2-MIB::sysORID.1 = OID: IF-MIB::ifMIB Variable: Example 5: Sending an Inform Request The following is an example of sending an Inform request: snmptest -v 2c -c public snmptrapd_host:162 Variable: $I Request type is Inform Request (Are you sending to the right port?) Variable: system.sysContact.0 Type [i|u|sIx|d|n|o|t|a]: s Value: x12345 Variable: Inform Acknowledged Variable: The snmptrapd_host will show: snmptrapd_host [<ip address>]: Trap SNMPv2-MIB::sysContact.0 = STRING: x12345 Example 6: Sending an SNMPv2 Trap Request The following is an example of sending an SNMPv2 Trap request: snmptest -v 2c -c public snmptrapd_host:162 Variable: $T Request type is SNMPv2 Trap Request (Are you sending to the right port?) Variable: system.sysLocation.0 Type [i|u|s|x|d|n|o|t|a]: s Value: building a Variable: The snmptrapd_host will show: snmptrapd_host [<ip address>]: Trap SNMPv2-MIB::sys.0 = STRING: building A EXIT STATUS
0 Successful completion. 1 A usage syntax error. A usage message is displayed. Also used for timeout errors. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWsmcmd | +-----------------------------+-----------------------------+ |Interface Stability |External | +-----------------------------+-----------------------------+ SEE ALSO
snmpcmd(1M), snmpget(1M), snmpset(1M), snmp_variables(4), attributes(5) SunOS 5.10 23 Jan 2004 snmptest(1M)
All times are GMT -4. The time now is 04:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy