Results 1 to 2 of 2
Hi all,
How can I catch/supress errors from psql? I've got a simple program that will query psql, if a table is there it returns a 1 else returns a ...
- 06-23-2010 #1Just Joined!
- Join Date
- Jun 2010
- Posts
- 11
Supress ERROR from SH running psql
Hi all,
How can I catch/supress errors from psql? I've got a simple program that will query psql, if a table is there it returns a 1 else returns a 0. The problem is I get the error message as well. How can I trap the error and just get the 1 or 0 to return?
This is a simplified example, I realize I could use the pg tables in this example but for my req I need to run it this way.
Code:#!/bin/sh # # #run select dbtest=`psql -U test -d test -q -t -c "select 1 from test_a;"` #if 1 pass 1 else 0 if [ $dbtest = "1" ] ; then echo "1" else echo "0" fi
- 01-05-2011 #2Just Joined!
- Join Date
- Jan 2011
- Posts
- 1
try to use this.
#!/bin/sh
#
#
#run select
dbtest=`psql -U test -d test -q -t -c "select 1 from test_a;"`
val=`echo $?`
if [ $val = "0" ] ; then
echo "Pass"
else
echo "failed"
fi
echo15


Reply With Quote