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?
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:
I am assuming that the
isqlprogram 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.Then I’d use:
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?