开发者

Grab SQL being executed in a shell script

Given a shell script containing a bunch of SQL statements, is there an option to redirect just the SQL statements to stdout/file?

The structure of the script is something like this:

...

for i in *list*  
do  
  isql *credentials etc* <<EOF > a.out  开发者_开发百科
  select *about 100 cols*  
from $i + "_TAB"  
go  
EOF  
done 

...

Query has been simplified, and is quite complex in reality.

How can I grab the actual statements that are executed when I run this script?

Much appreciate your help.


The -e (and often with -n) option will echo the input Sybase document for isql although you will get the output as well. If you want to not have the output - selects etc you will need to write a function called isql that will echo the command line to one file and run the isql to another (easier in perl or python)


Use a variable to hold your here doc, then you can echo it.

for i in *list*  
do  
    read -r -d '' select <<-EOF
        select *about 100 cols*  
        from $i + "_TAB"  
        go  
        EOF  
    isql *credentials etc* <<< "$select"
    echo "$select" > a.out
done

The hyphen after the << allows you to indent the here doc, but only with actual tabs. Tabs converted to spaces, as is done automatically by some editors, will not work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜