Sponsored Content
Top Forums Shell Programming and Scripting Loop to define variables in KSH Post 302589393 by gbala on Wednesday 11th of January 2012 01:12:53 PM
Old 01-11-2012
Loop to define variables in KSH

Hi,

I am trying to use a database to store configurations in an environment definition scripts to make the configurations easily modifiable. (long story short - it is an easier process to make changes in the db than trying to deploy a file). The values will be stored in the database in the following format

parameter_name parameter_value
ABC value_of_abc
DEF value_of_def

I can do the first part to fetch the data and loop through. I could not
think of a way to define the variables and export it. In other words, after
the script is run, the variable ABC should have "value_of_abc" and the variable DEF should have "value_of_def". The name of the variable itself comes from the database.

Would appreciate any help from experienced users.

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

variables in ksh

I'm new to unix scripting. How would I go about pulling the first 3 characters from a variable in ksh and storing in another variable? Thanks. (9 Replies)
Discussion started by: steve6368
9 Replies

2. Shell Programming and Scripting

Exactly How can we define "sh ksh csh &bash"

Hi - I m prashant. I m new in UNIX&LINUX world. I want to ask that how can we define the shell in Linux like bash,ksh,csh in Linux. What is the use of these shells. I know there are mny experts on net if you can tell me then please do me this favour and tell me about this topic. ... (1 Reply)
Discussion started by: prashantsingh
1 Replies

3. Shell Programming and Scripting

How to define array in Bourne shell , csh & ksh

Dear friends... Kindly if any one can help me to know the differences in definning & retreiving data from arrays in the sh,csh & ksh. I always facing problems in this issue. thanks...:) BR (3 Replies)
Discussion started by: ahmad.diab
3 Replies

4. Shell Programming and Scripting

Is there a better way I could have run this loop. (For loop with two variables)

Sorry for such a dreadful title, but I'm not sure how to be more descriptive. I'm hoping some of the more gurutastic out there can take a look at a solution I came up with to a problem, and advice if there are better ways to have gone about it. To make a long story short around 20K pieces of... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

5. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

6. Shell Programming and Scripting

ksh - for loop with variables

Hi, I 'm trying to send an e-mail for every different line in the .txt for i in {1..$variable} do sed -n "/$i$/p" text.txt done I have two problems about this. First one is that for loop doesn't work and the second one is that i cant get the output of sed (4 Replies)
Discussion started by: ozum
4 Replies

7. UNIX for Dummies Questions & Answers

Define variables with UNIX script

oopps! I Meant "Define Variables within a UNIX Script" What would be the best way to define a variable in a unix shell script so anyone who views this script doesn't know what value is assigned to that variable. some other location... a="/usr/lib/fileA" Unix script... sed... (5 Replies)
Discussion started by: macastor
5 Replies

8. Shell Programming and Scripting

Using a script to define variables and run multiple other scripts in succession.

I'm pretty new to scripting in Korn shell so please forgive me... What I'm trying to do is to create a script that calls multiple other ksh scripts and defines variables for text files. I need it to define my user defined variables (file paths, date & time stamps, etc that are currently in... (1 Reply)
Discussion started by: bluejwxn8
1 Replies

9. Shell Programming and Scripting

Define Variables

Hi, I just define the variable in script and use those script in another script but the variable not recognize. test1.sh #!/bin/bash DB="test_db" USR="test_user" PWD="test_pwd" HST="24.254.87.12" test2.sh #!/bin/bash ./test1.sh mysql -u $USR -p $PWD -h $HST... (2 Replies)
Discussion started by: fspalero
2 Replies

10. Shell Programming and Scripting

ksh While Loop - passing variables to functions

I'm reading a text file using a while loop but when I call a function from within this loop it exits that same iteration … even though there are many more lines in the file to be read. I thought it was something to do with the IFS setting but it appears that a function call (when run... (3 Replies)
Discussion started by: user052009
3 Replies
RRDGRAPH_LIBDBI(1)						      rrdtool							RRDGRAPH_LIBDBI(1)

NAME
rrdgraph_libdbi - fetching data for graphing in rrdtool graph via libdbi SYNOPSIS
<rrdfile> = sql//<libdbi driver>/<driver-option-name>=<driver-option-value>/...[/rrdminstepsize=<stepsize>][/rrdfillmissing=<fill missing n samples>]//<table>/<unixtimestamp column>/<data value column>[/derive]/<where clause 1>/.../<where clause n> DESCRIPTION
This pseudo-rrd-filename defines a sql datasource: sql// magic cookie-prefix for a libdbi type datasource <libdbi driver> which libdbi driver to use (e.g: mysql) <driver-option-name>=<driver-option-value> defines the parameters that are required to connect to the database with the given libdbi driver (These drivers are libdbi dependent - for details please look at the driver documentation of libdbi!) /rrdminstepsize=<minimum step size> defines the minimum number of the step-length used for graphing (default: 300 seconds) /rrdfillmissing=<fill missing steps> defines the number of steps to fill with the last value to avoid NaN boxes due to data-insertation jitter (default: 0 steps) <table> defines the table from which to fetch the resultset. If there is a need to fetch data from several tables, these tables can be defined by separating the tablenames with a "+" hex-type-encoding via %xx are translated to the actual value, use %% to use % <[*]unixtimestamp column> defines the column of E<lt>tableE<gt> which contains the unix-timestamp - if this is a DATETIME field in the database, then prefix with leading '*' hex-type-encoding via %xx are translated to the actual value, use %% to use % <data value column> defines the column of E<lt>tableE<gt> which contains the value column, which should be graphed hex-type-encoding via %xx are translated to the actual value, use %% to use % /derive defines that the data value used should be the delta of the 2 consecutive values (to simulate COUNTER or DERIVE type datasources) /<where clause(s)> defines one (ore more) where clauses that are joined with AND to filter the entries in the <lt>table<gt> hex-type-encoding via %xx are translated to the actual value, use %% to use % the returned value column-names, which can be used as ds-names, are: min, avg, max, count and sigma are returned to be used as ds-names in your DS definition. The reason for using this is that if the consolidation function is used for min/avg and max, then the engine is used several times. And this results in the same SQL Statements used several times EXAMPLES
Here an example of a table in a MySQL database: DB connect information dbhost=127.0.0.1 user=rrd password=secret database=rrd here the table: CREATE TABLE RRDValue ( RRDKeyID bigint(20) NOT NULL, UnixTimeStamp int(11) NOT NULL, value double default NOT NULL, PRIMARY KEY (RRDKeyID,UnixTimeStamp) ); and the RRDKeyID we want to graph for is: 1141942900757789274 The pseudo rrd-filename to access this is: "sql//mysql/host=127.0.0.1/dbname=rrd/username=rrd/password=secret//RRDValue/UnixTimeStamp/value/RRDKeyID=1141464142203608274" To illustrate this here a command to create a graph that contains the actual values. DS_BASE="sql//mysql/host=127.0.0.1/dbname=rrd/username=rrd/password=passwd//RRDValue/UnixTimeStamp/value/RRDKeyID=1141942900757789274" rrdtool graph test.png --imgformat=PNG --start=-1day --end=+3hours --width=1000 --height=600 "DEF:min=$DS_BASE:min:AVERAGE" "LINE1:min#FF0000:value" "DEF:avg=$DS_BASE:avg:AVERAGE" "LINE1:avg#00FF00:average" "DEF:max=$DS_BASE:max:AVERAGE" "LINE1:max#FF0000:max" "DEF:sigma=$DS_BASE:sigma:AVERAGE" "CDEF:upper=avg,4,sigma,*,+" "LINE1:upper#0000FF:+4 sigma" "CDEF:lower=avg,4,sigma,*,-" "LINE1:lower#0000FF:-4 sigma" NOTES
* Naturally you can also use any other kind of driver that libdbi supports - e.g postgres, ... * From the way the data source is joined, it should also be possible to do joins over different tables (separate tables with "," in table and add in the WHERE Clauses the table equal joins. This has not been tested!!!) * It should also be relatively simple to add to the database using the same data source string. This has not been implemented... * The aggregation functions are ignored and several data columns are used instead to avoid querying the same SQL several times when minimum, average and maximum are needed for graphing... * for DB efficiency you should think of having 2 tables, one containing historic values and the other containing the latest data. This second table should be kept small to allow for the least ammount of blocking SQL statements. Whith mysql you can even use myisam table-type for the first and InnoDB for the second. This is especially interresting as with tables with +100M rows myisam is much smaller then InnoDB. * To debug the SQL statements set the environment variable RRDDEBUGSQL and the actual SQL statements and the timing is printed to stderr. BUGS
* at least on Linux please make sure that the libdbi driver is explicitly linked against libdbi.so.0 check via ldd /usr/lib/dbd/libmysql.so, that there is a line with libdbi.so.0. otherwise at least the perl module RRDs will fail because the dynamic linker can not find some symbols from libdbi.so. (this only happens when the libdbi driver is actually used the first time!) This is KNOWN to be the case with RHEL4 and FC4 and FC5! (But actually this is a bug with libdbi make files!) * at least version 0.8.1 of libdbiexhibits a bug with BINARY fields (shorttext,text,mediumtext,longtext and possibly also BINARY and BLOB fields), that can result in coredumps of rrdtool. The tool will tell you on stderr if this occures, so that you know what may be the reason. If you are not experiencing these coredumps, then set the environment variable RRD_NO_LIBDBI_BUG_WARNING, and then the message will not get shown. AUTHOR
Martin Sperl <rrdtool@martin.sperl.org> 1.4.7 2009-10-14 RRDGRAPH_LIBDBI(1)
All times are GMT -4. The time now is 06:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy