LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 03-09-2017, 04:50 AM   #1
slayer_1994
Member
 
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 ]
then
duplicate_user_status="No Duplicate IP's Found"
else
duplicate_user_status="Duplicate IP's Found"

fi

if [ "$duplicate_user_count" -gt 1 ]
then
echo "mail sent to SAP Tooling Team" | mail -s "$duplicate_user_list" alex.simpson1@britishgas.co.uk


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
r3sistance
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

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

Code:
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
Code:
$ myvar="test";mylen=${#myvar};echo $mylen
4

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


Reply

Tags
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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:10 PM.

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