From: | "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com> |
---|---|
To: | cpayne(at)magigames(dot)net |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Need help with bash script and postgresql |
Date: | 2007-07-23 14:13:41 |
Message-ID: | dcc563d10707230713y6b45bf37gb98b575569b721c6@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 7/23/07, Chuck Payne <cpayne(at)magigames(dot)net> wrote:
>
> Hey,
>
> I have spend the last several days looking for a website or how to that
> would show me how to call postgresql in bash script. I know that in mysql I
> can do like this
>
> for i in `cat myfile.txt` ; do mysql -uxxx -pxxxx -Asse mydatabase "insert
> into mytable (aaa,bbb) values ("xxx", "yyy");"
>
> I have tried to do what with pgsql and it not working. I have looked at my
> two books I have and they are very limited.
>
> Can some what tell if postgre has flag like -Asse? Or show me a simple
> script they have do that is kinda like above.
Sometimes it's handy to process multiple lines at a time and process
each piece of data. Here's a bit of a script, simplified, that we use
to monitor our application where I work.
echo $newquery | psql -h pg -U report -Atp5432 -F" " productiondb >
/tmp/$$stat.tmp;
t=/tmp/$$stat.tmp;
# If there's no response, exit
if [[ -z $t ]]; then
rm /tmp/$$stat.tmp
exit;
fi;
while read line
do
arr=($line)
tc=${arr[0]}
frate=${arr[1]}
fails=${arr[2]}
if [[ frate -gt 25 && tc -gt 5 ]]; then
do something here
fi;
if [[ fails -gt 10 && tc -gt 5 ]]; then
do something here
fi;
fi;
done < /tmp/$$stat.tmp
This script reads one line at a time from the $$stat.tmp file and
explodes each space separated element and assigns them to variables
you can perform tests on.
From | Date | Subject | |
---|---|---|---|
Next Message | polen.t2006 | 2007-07-23 14:50:35 | regexp_replace |
Previous Message | Raymond O'Donnell | 2007-07-23 13:56:38 | Re: Need help with bash script and postgresql |