Sponsored Content
Top Forums Shell Programming and Scripting evaluating a variable inside a variable Post 302578435 by felipe.vinturin on Thursday 1st of December 2011 12:45:02 PM
Old 12-01-2011
This:
Code:
# eval "myVar=\$${i}"
# echo "myVar: [${myVar}]"

"myVar" will have the content of variable pointed by: "${i}". But be careful: eval is evil!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh: A part of variable A's name is inside of variable B, how to update A?

This is what I tried: vara=${varb}_count (( vara += 1 )) Thanks for help (4 Replies)
Discussion started by: pa3be
4 Replies

2. Shell Programming and Scripting

How to replace variable inside the variable

hi sir, i need your help for this script inside /rnmucdr/ednms05/ken/xMNBDF045_Script.sql content variable like this select * from invoice where bill_date=$BILLDATE and startNum=$STARTPARTNNUM and total_partn=$TOTALPARTN if i just paste this replace with the $SCRIPT it works great,if... (31 Replies)
Discussion started by: mani_um
31 Replies

3. UNIX for Dummies Questions & Answers

passing a variable inside a variable to a function

I would like to know how to pass a variable inside a variable to a function. sample code below -------------- for x in 1 9 do check_null $C$x ##call function to check if the value is null if then echo "line number:$var_cnt,... (2 Replies)
Discussion started by: KingVikram
2 Replies

4. Shell Programming and Scripting

Bash: evaluating $? variable (if statement)

Hello, i'm unable to write a correct if... statement to evaluate the $? variable. Could anybody send to me an example? for example, this lines of code didn't work... if ; then etc etc if ; then etc etc Thank you in advanced. (5 Replies)
Discussion started by: aristegui
5 Replies

5. Shell Programming and Scripting

K Shell evaluating value to a variable

Hi, I have the following requirement. V="First" R="V" echo $$R The output should be First. How do i achieve this. how do we evaluate the $R and evaluate it to $V as $R contains V and $V is First. Thanks Vijay (2 Replies)
Discussion started by: vijaykrc
2 Replies

6. Shell Programming and Scripting

passing a variable inside another variable.

Any help would be great. I know this is a dumb way of doing this, but I would like to know if there is a solution doing it this way. I'm very new at this and I'd like to learn more. Thanks! :D:D count=0 while ; do echo "enter your name" read name_$count let count=count+1 done ... (2 Replies)
Discussion started by: reconflux
2 Replies

7. Shell Programming and Scripting

variable inside variable inside loop headache

Hi Gurus I have a file called /tmp/CMDB which looks like this serial: 0623AN1208 hostname: server1 model: x4100 assetID: 1234 I am writing a for loop that will go through this file line by line creating a variable of itself. Using the first iteration of the loop (i.e. the first line) as... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

8. Shell Programming and Scripting

Evaluating a variable

Does anyone know of a way to force a variable name held in another variable to return the value of the first variable? Best if I give an example, that does not work: /usr/local/bin >cat mike.sh NUM1ref=16 NUM2ref=32 echo "==============" for VAR in NUM1 NUM2 do XXXX=${VAR}ref echo $XXXX... (4 Replies)
Discussion started by: mikejordan
4 Replies

9. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

10. Shell Programming and Scripting

To print value for a $variable inside a $variable or file

Hi guys, I have a file "abc.dat" in below format: FILE_PATH||||$F_PATH TABLE_LIST||||a|b|c SYST_NM||||${SRC_SYST} Now I am trying to read the above file and want to print the value for above dollar variables F_PATH and SRC_SYST. The problem is it's reading the dollar variables as... (5 Replies)
Discussion started by: abcabc1103
5 Replies
snmp_generic(3erl)					     Erlang Module Definition						snmp_generic(3erl)

NAME
snmp_generic - Generic Functions for Implementing SNMP Objects in a Database DESCRIPTION
The module snmp_generic contains generic functions for implementing tables (and variables) using the SNMP built-in database or Mnesia. These default functions are used if no instrumentation function is provided for a managed object in a MIB. Sometimes, it might be necessary to customize the behaviour of the default functions. For example, in some situations a trap should be sent if a row is deleted or modified, or some hardware is to be informed, when information is changed. The overall structure is shown in the following figure: +---------------+ | SNMP Agent | +- - - - - - - -+ | MIB | +---------------+ | Association file (associates a MIB object with | snmp_generic:table_funct | snmp_generic:variable_func) +--------------------------------------+ | snmp_generic | Support for get-next, | | RowStatus operations +----------------------+---------------+ | snmpa_local_db | Mnesia | Database +--------------+-------+---------------+ | dets | ets | | (persistent) | | +--------------+-------+ Each function takes the argument NameDb , which is a tuple {Name, Db} , to identify which database the functions should use. Name is the symbolic name of the managed object as defined in the MIB, and Db is either volatile , persistent , or mnesia . If it is mnesia , all vari- ables are stored in the Mnesia table snmp_variables which must be a table with two attributes (not a Mnesia SNMP table). The SNMP tables are stored in Mnesia tables with the same names as the SNMP tables. All functions assume that a Mnesia table exists with the correct name and attributes. It is the programmer's responsibility to ensure this. Specifically, if variables are stored in Mnesia, the table snmp_vari- ables must be created by the programmer. The record definition for this table is defined in the file snmp/include/snmp_types.hrl . If an instrumentation function in the association file for a variable myVar does not have a name when compiling an MIB, the compiler gener- ates an entry. {myVar, {snmp_generic, variable_func, [{myVar, Db]}}. And for a table: {myTable, {snmp_generic, table_func, [{myTable, Db]}}. DATA TYPES
In the functions defined below, the following types are used: name_db() = {name(), db()} name() = atom() db() = volatile | persistent | mnesia row_index() = [int()] columns() = [column()] | [{column(), value()}] column() = int() value() = term() row_index() : Denotes the last part of the OID which specifies the index of the row in the table (see RFC1212, 4.1.6 for more information about INDEX). columns() : Is a list of column numbers in the case of a get operation, and a list of column numbers and values in the case of a set operation. EXPORTS
get_status_col(Name, Cols) get_status_col(NameDb, Cols) -> {ok, StatusVal} | false Types Name = name() NameDb = name_db() Cols = columns() StatusVal = term() Gets the value of the status column from Cols . This function can be used in instrumentation functions for is_set_ok , undo or set to check if the status column of a table is modi- fied. get_index_types(Name) Types Name = name() Gets the index types of Name This function can be used in instrumentation functions to retrieve the index types part of the table info. table_func(Op1, NameDb) table_func(Op2, RowIndex, Cols, NameDb) -> Ret Types Op1 = new | delete Op2 = get | next | is_set_ok | set | undo NameDb = name_db() RowIndex = row_index() Cols = columns() Ret = term() This is the default instrumentation function for tables. * The new function creates the table if it does not exist, but only if the database is the SNMP internal db. * The delete function does not delete the table from the database since unloading an MIB does not necessarily mean that the table should be destroyed. * The is_set_ok function checks that a row which is to be modified or deleted exists, and that a row which is to be created does not exist. * The undo function does nothing. * The set function checks if it has enough information to make the row change its status from notReady to notInService (when a row has been been set to createAndWait ). If a row is set to createAndWait , columns without a value are set to noinit . If Mnesia is used, the set functionality is handled within a transaction. If it is possible for a manager to create or delete rows in the table, there must be a RowStatus column for is_set_ok , set and undo to work properly. The function returns according to the specification of an instrumentation function. table_get_elements(NameDb, RowIndex, Cols) -> Values Types NameDb = name_db() RowIndex = row_index() Cols = columns() Values = [value() | noinit] Returns a list with values for all columns in Cols . If a column is undefined, its value is noinit . table_next(NameDb, RestOid) -> RowIndex | endOfTable Types NameDb = name_db() RestOid = [int()] RowIndex = row_index() Finds the indices of the next row in the table. RestOid does not have to specify an existing row. table_row_exists(NameDb, RowIndex) -> bool() Types NameDb = name_db() RowIndex = row_index() Checks if a row in a table exists. table_set_elements(NameDb, RowIndex, Cols) -> bool() Types NameDb = name_db() RowIndex = row_index() Cols = columns() Sets the elements in Cols to the row specified by RowIndex . No checks are performed on the new values. If the Mnesia database is used, this function calls mnesia:write to store the values. This means that this function must be called from within a transaction ( mnesia:transaction/1 or mnesia:dirty/1 ). variable_func(Op1, NameDb) variable_func(Op2, Val, NameDb) -> Ret Types Op1 = new | delete | get Op2 = is_set_ok | set | undo NameDb = name_db() Val = value() Ret = term() This is the default instrumentation function for variables. The new function creates a new variable in the database with a default value as defined in the MIB, or a zero value (depending on the type). The delete function does not delete the variable from the database. The function returns according to the specification of an instrumentation function. variable_get(NameDb) -> {value, Value} | undefined Types NameDb = name_db() Value = value() Gets the value of a variable. variable_set(NameDb, NewVal) -> true | false Types NameDb = name_db() NewVal = value() Sets a new value to a variable. The variable is created if it does not exist. No checks are made on the type of the new value. Returns false if the NameDb argument is incorrectly specified, otherwise true . EXAMPLE
The following example shows an implementation of a table which is stored in Mnesia, but with some checks performed at set-request opera- tions. myTable_func(new, NameDb) -> % pass unchanged snmp_generic:table_func(new, NameDb). myTable_func(delete, NameDb) -> % pass unchanged snmp_generic:table_func(delete, NameDb). %% change row myTable_func(is_set_ok, RowIndex, Cols, NameDb) -> case snmp_generic:table_func(is_set_ok, RowIndex, Cols, NameDb) of {noError, 0} -> myApplication:is_set_ok(RowIndex, Cols); Err -> Err end; myTable_func(set, RowIndex, Cols, NameDb) -> case snmp_generic:table_func(set, RowIndex, Cols, NameDb), {noError, 0} -> % Now the row is updated, tell the application myApplication:update(RowIndex, Cols); Err -> Err end; myTable_func(Op, RowIndex, Cols, NameDb) -> % pass unchanged snmp_generic:table_func(Op, RowIndex, Cols, NameDb). The .funcs file would look like: {myTable, {myModule, myTable_func, [{myTable, mnesia}]}}. Ericsson AB snmp 4.19 snmp_generic(3erl)
All times are GMT -4. The time now is 06:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy