Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6624169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:37:12+00:00 2026-05-25T21:37:12+00:00

Since I am new to unix scripting. I am running a SQL statement in

  • 0

Since I am new to unix scripting. I am running a SQL statement in ASE ISQL, and if SQL statement gives some result then I need to mail that result to a particular users. And if SQL is not returning any result then mail should not be sent.
The Sample Script I have wriiten is:

#!/bin/ksh
isql -U$DBO -S$DSQUERY -D$DBNAME -P$PASSWORD << END 
go
select * from 'Table'
go
if (@@rowcount !=0)

mailx -s "Hello" XYZ@gmail.com 


END

Please let me know where I am going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:37:13+00:00Added an answer on May 25, 2026 at 9:37 pm

    I think you need to capture the output of the SQL into a shell variable, and then test the result before sending the email, roughly like:

    #!/bin/ksh
    num=$(isql -U$DBO -S$DSQUERY -D$DBNAME -P$PASSWORD << END 
    select count(*) from 'Table'
    go
    END
    )
    
    if [ "$num" -gt 0 ]
    then mailx -s "Hello" XYZ@gmail.com < /dev/null
    fi
    

    I am assuming that the isql program will only print the number and not any headings or other information. If it is more verbose, then you have to do a more sensitive test.

    Note, too, that COUNT(*) is quicker and more accurately what you’re after than your ‘select everything and count how many rows there were’ version.


    Actually my problem is if my SQL statement is returning any result then only that resultset should be sent in a mail.

    Then I’d use:

    #!/bin/ksh
    tmp=${TMPDIR:-/tmp}/results.$$
    trap "rm -f $tmp; exit 1" 0 1 2 3 13 15
    
    isql -U$DBO -S$DSQUERY -D$DBNAME -P$PASSWORD << END > $tmp
    select * from 'Table'
    go
    END
    
    if [ -s $tmp ]
    then mailx -s "Hello" XYZ@gmail.com < $tmp || exit 1
    fi
    rm -f $tmp
    trap 0
    exit 0
    

    This captures the results in a file. If the file is not empty (-s) then it sends the file as the body of an email. Please change the subject to something more meaningful. Also, are you sure it is a good idea to send corporate email to a Gmail account?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since new Entity Framework version I got from nuget broke some of my tests,
I am working on a small MFC application..since am new to MFC I am
I am playing with F# in VS2010 beta2, and since I am new to
Since starting at a new company I've noticed that they use unity cpp files
since Windows Vista there is an new Win32-API call CreateSymbolicLink to create a symbolic
Ever since I installed emacs on a new machine I have seen an ugly
Since Rails 2.1, if you define a new column in a migration with the
I'm new to this SCM, but since SVN is gaining popularity I was going
Since http is stateless, every request to an app creates a new object. How
I am new to Oracle. Since we have rewritten an earlier application , we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.