Re: How to query pgsql from a BASH script ?
От | Michelle Konzack |
---|---|
Тема | Re: How to query pgsql from a BASH script ? |
Дата | |
Msg-id | 20050403153447.GG15347@freenet.de обсуждение исходный текст |
Ответ на | Re: How to query pgsql from a BASH script ? ("Sean Davis" <sdavis2@mail.nih.gov>) |
Список | pgsql-general |
Am 2005-04-03 10:41:06, schrieb Sean Davis: > Michelle, > > There may be other answers for this, but if you need to connect 2-3 times > per second, you probably need a persistent connection which, as far as I > know, can't be obtained (and maintained) from bash. Is there a reason not > to do this from the server side or even from a standard client-side > language like perl, java, or C? First: I have no clue about perl and java. Second: I use C, but never used in conjunction with a database I the datsbase should queried from, e.g., a procmailrc and check for IP addresses and much more. Most TABLES has only 2 or 3 COLS The problem are the ROWS of the database. So I am searching for a simpel solution to access the DB from BASH OK, I have already codes stuff in php and the RETVAL was simpel "VAL1 VAL2 VAL3" which I can cut into: RETVAL=`php pg_query.php $SERVER $DB $TABLE $COL $SEARCH` if [ $? == "1" ] ; then exit 1 ; fi VAL1=`echo $RETVAL |cut -d " " -f1` VAL2=`echo $RETVAL |cut -d " " -f2` VAL3=`echo $RETVAL |cut -d " " -f3` where the pg_query.php has serched only in the given $COL and returnd the whole $ROW as RETVAL. I was thinkg that such tool already exist in C. But if you have a DB of 10.000 lines, the above examle will be faster then a BASH solution with a file like RETVAL=`grep "^$SEARCH" $DB_FILE` if [ $? == "1" ] ; then exit 1 ; fi VAL1=`echo $RETVAL |cut -d " " -f1` VAL2=`echo $RETVAL |cut -d " " -f2` VAL3=`echo $RETVAL |cut -d " " -f3` and pgsql can be updated concurently, a $DB_FILE not. Oh yes, from time to time a have realy need for a DB even in stupid BASH scripts because it makle the life easier. And the other think is, the first $COL is every time UNIQ. > Sean Greetings Michelle -- Linux-User #280138 with the Linux Counter, http://counter.li.org/ Michelle Konzack Apt. 917 ICQ #328449886 50, rue de Soultz MSM LinuxMichi 0033/3/88452356 67100 Strasbourg/France IRC #Debian (irc.icq.com)
Вложения
В списке pgsql-general по дате отправления: