How can I pass the sqsh command and get the output to a file in one go?

I am trying to set up a simple loop to periodically query a database table in bash. Usually it seems to me what to do:

sqsh -s SERV -U user -P passwd -D db -L bcp_colsep=','

then in sqsh i should enter:

select * from some_table where foo=bar
\go -m bcp > /path/to/output.out

I tried to use the parameter -Cfor sqsh to pass in the command as follows:

sqsh -s SERV -U user -P passwd -D db -L bcp_colsep=',' -C 'select * from some_table where foo=bar \go -m bcp > /path/to/output.out'

but I keep getting:

Incorrect syntax near '\'.

How can I get the desired effect?

+4
source share
1 answer

-C SQL sqsh, \go . "bcp", "style = bcp" -L -mbcp sqsh -o . , :

sqsh -S SERV -U user -P passwd -D db -L bcp_colsep=',' -m bcp \
-C 'select * from some_table where foo=bar' > /path/to/output.out

HTH,

+9

Source: https://habr.com/ru/post/1524346/


All Articles