From: | Paul Silveira <plabrh1(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: shell script to populate array values |
Date: | 2006-12-12 17:28:32 |
Message-ID: | 7837622.post@talk.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thanks Susan... I really appreciate your answer and helping me do what I
wanted to do...
I posted the code I was working on here...
http://people.planetpostgresql.org/paul/
It's a pretty cool script and although it's not even done yet, I'm sure it
could be useful to anyone wanting to do the same thing...
-Paul
Paul Silveira wrote:
>
> Hello,
>
> I would like to create a shell script that would populate two variables
> with the return of a SELECT statement that would return two attributes...
>
> For example...
>
> #!/bin/bash
> SERVER_NAMES=`psql Admin -Upostgres -hMYSERVER -t -c"SELECT servername,
> instanceport from server where serverclass = 3 and isactive = 'True' ";`
>
>
> As you can see, I'm returning the servername "and" the instanceport from
> the server table. This will later allow me to create psql commands to
> connect to each server dynamically.
>
> I had the script working correctly when I was just running it for the
> server name as below...
> #!/bin/bash
> SERVER_NAMES=`psql Admin -Upostgres -hMYSERVER -t -c"SELECT servername
> from server where serverclass = 3 and isactive = 'True' ";`
>
>
> Does anyone know the easiest way to get both values out of some variables
> that I could set?
>
> Later in the script, I'm creating a for loop and iterating through the
> server names and would like to build connection strings dynamically with
> the results from the select string...
>
>
>
> for i in $SERVER_NAMES
> do
> psql -Upostgres -h$i -p$i -A -t -c"SELECT '$i', '$BATCHTIME', name,
> setting, category, short_desc, context, vartype, source, min_val, max_val
> FROM pg_settings;" | psql Admin -Upostgres -hMYSERVER -t -c"COPY
> serverconfigsetting FROM STDIN WITH DELIMITER '|' NULL AS '';"
> echo "Done with $i"
> done
>
>
> As you can see I have "-h$i -p$i" in the script for the host and port.
> Again the script worked fine when I just had the -h(at)i in there...
>
> I know that the current forloop is incorrect specifiying the $i twice but
> I just put that in there to show an example of what I was hoping to do...
> It would probably be more accessing the array value like -h$i[0:0]
> -p$i[0:1] in pseudo code for accessing array values.
>
> Thanks in advance,
>
> Paul
>
>
>
>
>
>
--
View this message in context: http://www.nabble.com/shell-script-to-populate-array-values-tf2796502.html#a7837622
Sent from the PostgreSQL - general mailing list archive at Nabble.com.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2006-12-12 17:30:07 | Re: Why DISTINCT ... DESC is slow? |
Previous Message | Bruce Momjian | 2006-12-12 17:25:29 | Re: Restore database from files (not dump files)? |