dbaccess script

Posted on 2011-04-27
Last Modified: 2012-05-11
I am looking to automate a query in our database using dbaccess.  I have the start of the file and the query but am not sure how to automate this.  My files starts with:

dbaccess -qn  (this brings me to start my select statement but I've been looking around the internet and don't see how to add the select statement in so it automatically runs.  Manually everything works fine).  Also, I would like to save this query to a file on the server.

Any help would be appreciated.
Question by:cbones
    LVL 16

    Expert Comment

    by:Bryan Butler
    Can you put your commands in a file or to run from the command line, try:
    dbaccess dbname << select here

    Here's some links that might help.
    LVL 16

    Accepted Solution

    LVL 7

    Assisted Solution

    Make a script file, say "runsql", with the line below.
    Give it an execution permission. (type "chmod u+x runsql" at a shell prompt)
    Save your sql statements in a file, say "my_queries.sql"
    Now type "runsql your_db_name my_queries.sql" at a prompt.
    The result will be displayed and also saved in "my_queries.sql.out"

    dbaccess -e $1 $2 | tee $2.out 2>&1

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Title # Comments Views Activity
    T-SQL Edit Top 5000 Rows - Query? 1 29
    Divide by Zero Error in SQL 7 25
    Update field in order 21 93
    shell script to send sms 2 34
    Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
    Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now