Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

commandline dbaccess

Status
Not open for further replies.

sweetsgup

Programmer
Oct 22, 2000
6
0
0
MY
hi, i am pretty new to informix and would appreciate an answer to this doubt..I would like to know how can i batch execute multiple .sql files from commandline using dbaccess and then direct the output to a file. Thanks in advance.
[sig][/sig]
 
In Unix create a command file containing the following;

dbaccess 'DBNAME' -<<!
'SQL #1';
'SQL #2';
!

If the command file you created is called mysql.sh run it as follows;

nohup mysql.sh &

This will execute SQL #1 followed by SQL #2 (against database DBNAME) and save the output in a file named nohup.out

Make sure the last ! is the first character in the first column. [sig][/sig]
 
Thanks a lot Richman, I have just one more question, is it possible that i can package some scriptfiles and the .sql files together in the same commandfile and execute it, will the scripts get executed as well? [sig][/sig]
 
If I understand you correctly the answer is yes. The piece of code I supplied can be wrapped with unix shell commands. The stuff in between the !'s are for the database only - the remainder is for the shell. e.g.;

echo &quot;`date` Selecting rows from table ABC . . .&quot;

dbaccess 'DBNAME' -<<!
unload to abc.unl
select
*
from ABC
;
!

echo &quot;`date` Selected rows from table ABC . . .&quot;

I wrote the echo commands (in this case) to tell me what the sql is doing. Try it with your shell script(s). Happy Halloween!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top