Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-09-2017, 04:50 AM   #1
Registered: Feb 2017
Posts: 38

Rep: Reputation: Disabled
Email Alert in UNIX

Hi There

I have to wrote a script where I am able to echo a result of an SQL script, however I want to be able to send an email to myself when it is more than 0 (so whenever a value is returned) is this possible?

I tried one way from looking on the web but this didn't work, I have added my script below:

duplicate_user_list=`psql cemdb admin -t -f /opt/ca/SAP_Tooling/sql/self_monitoring/duplicate_users.sql|sed '/^$/d' | awk '{print $1}'`
duplicate_user_count=`psql cemdb admin -t -f /opt/ca/SAP_Tooling/sql/self_monitoring/duplicate_users.sql|sed '/^$/d' | wc -l`

if [ "$duplicate_user_count" -eq 0 ]
duplicate_user_status="No Duplicate IP's Found"
duplicate_user_status="Duplicate IP's Found"


if [ "$duplicate_user_count" -gt 1 ]
echo "mail sent to SAP Tooling Team" | mail -s "$duplicate_user_list"

The count works fine and returns what is expected

Any help will be much appreciated

Many Thanks
Old 03-09-2017, 05:11 AM   #2
Senior Member
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
probably not the issue but I see one mistake

if [ "$duplicate_user_count" -gt 1 ]
should probably be

if [ "$duplicate_user_count" -ge 1 ]
or -gt 0

Also, if you are using BASH, there maybe a much easier way of getting the length
$ myvar="test";mylen=${#myvar};echo $mylen

Last edited by r3sistance; 03-09-2017 at 05:22 AM.


alert, code review, shell script, unix

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nagios - email notification - How to receive alert email? kumaran1983 Linux - Newbie 4 10-20-2011 06:12 AM
Email alert on password change officecase Linux - Security 2 01-20-2010 11:54 AM
No email alert from Nagios packets Linux - Software 0 10-18-2005 11:56 AM
Email Alert bad_andy Slackware 3 07-07-2005 09:45 PM
ALERT!!! ALERT!!! I messed up the UNIX!!! Firew Linux - Software 1 11-05-2001 11:48 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:33 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration