can't capture output error from isql shell script - firebird

I am trying to capture output and errors throw from shell script executed via isql. I've tried with the following code, but it doesn't work:
isql -q -i e:\test\script.sql e:\db\testdb.fdb -m -u sysuser -p xxx
I am looking for example how to use –m[erge_stderr] command.

Related

postgres script silently pass without any result

i am trying to execute psql queries from the bash command line passing password in following format
set PGPASSWORD=rtttttul psql -U ostgres -h localhost -d postgres -c "select * from logs" -o output.txt
Somehow my queries are not giving any results.i have tried to pass different queries or incorrect credentials but still script execute without any error.
If i don't pass password and try logging in to command prompt,everything works fine.
i want to check what basic thing i am missing above
Below command worked
PGPASSWORD=rtttttul psql -U ostgres -h localhost -d postgres -c "select * from logs" -o output.txt
remove set at start of command fixed it

Execute a .sql file with psql and make a log file

I'm dealing with psql for the first time and I need a command that executes a .sql file and after executing, it should make a .log file with the script output. I'm looking for something similar to this other command that I use with SQL Server:
sqlcmd -U userid -P password -S serveraddress -i path_to_the_sql_file -o path_where_to_save_log_file
Can you help me, please? :-)
I would spend some time at the psql page.
A quick example:
psql -U userid -h serveraddress -d some_db -f path_to_the_sql_file -L=path_where_to_save_log_file
With Postgres you need to connect to a database with a client. There are other options for inputting commands and capturing output at the link above.

How to log the output along with error messages to a file while running a script on psql command line on Freebsd OS?

On RHEL, the below command works:
psql -h hostname -U username -p port_no -d database -f /tmp/myfile.sql &> logfile01.txt
On FreeBSD, this throws error:
"Invalid null command"
Please suggest.
If you use this only on the command line then there is no need to change the shell.
To redirect stdout and stderr to a file in C-Shell synthax simply use ">& filename".
Different story is, if you want to write shell scripts. Bourne Shell and it's clones (like i.e. Bash) are better suited for writing script. See this Unix FAQ "Csh Programming Considered Harmful": http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
This redirection works in bash
&> logfile01.txt
, but it does not work in csh which is the default shell in FreeBSD.
# set | grep shell
shell /bin/csh
# ls -la &> logfile01.txt
Invalid null command.
Bash is not installed by default. You can install it
pkg install bash
and configure it as the default shell.

psql - write a query and the query's output to a file

In postgresql 9.3.1, when interactively developing a query using the psql command, the end result is sometimes to write the query results to a file:
boron.production=> \o /tmp/output
boron.production=> select 1;
boron.production=> \o
boron.production=> \q
$ cat /tmp/output
?column?
----------
1
(1 row)
This works fine. But how can I get the query itself to be written to the file along with the query results?
I've tried giving psql the --echo-queries switch:
-e, --echo-queries
Copy all SQL commands sent to the server to standard output as well.
This is equivalent to setting the variable ECHO to queries.
But this always echoes to stdout, not to the file I gave with the \o command.
I've tried the --echo-all switch as well, but it does not appear to echo interactive input.
Using command editing, I can repeat the query with \qecho in front of it. That works, but is tedious.
Is there any way to direct an interactive psql session to write both the query and the query output to a file?
You can try redirecting the stdout to a file directly from your shell (Win or Linux should work)
psql -U postgres -c "select 1 as result" -e nomedb >> hello.txt
This has the drawback of not letting you see the output interactively. If that's a problem, you can either tail the output file in a separate terminal, or, if in *nix, use the tee utility:
psql -U postgres -c "select 1 as result" -e nomedb | tee hello.txt
Hope this helps!
Luca
I know this is an old question, but at least in 9.3 and current versions this is possible using Query Buffer meta-commands shown in the documentation or \? from the psql console: https://www.postgresql.org/docs/9.3/static/app-psql.html
\w or \write filename
\w or \write |command
Outputs the current query buffer to the file filename or pipes it to the shell command command.
Please try this format as I got the output from the same:
psql -h $host -p $port -q -U $user -d $Dbname -c "SELECT \"Employee-id\",\"Employee-name\" FROM Employee_table" >> Employee_Date.csv
I need the output in a CSV file.

psql -o not what I expected (how to output db response to an output file)

I am creating a PostgreSQL database from the command line (i.e. using psql).
There are some errors in my SQL statements and I want to find out where the errors are occuring (too many objects to fill the screen buffer - so I need to save thios to file)
I have tried just about everything, from using the -o option, the -L option and using tee - I still cant capture the information that scrolls past on the screen.
How do I log this?
This is what I have tried so far:
psql -U -o dbcreate.log -f file.sql
psql -U -L dbcreate.log -f file.sql
psql -U -a -f file.sql | tee dbcreate.log
NONE of which results in the data flashing accross the screen being logged to file - how do I do this?
You need to redirect stderr. On Un*x and Linux:
psql ... 2>error.log
or both stdout and stderr:
psql ... &>error.log
On the other hand if you like to investigate the errors one by one:
psql -v ON_ERROR_STOP=1 ...
A helpful article about executing SQL scripts with psql - here.