Sponsored Content
Top Forums Shell Programming and Scripting Conditional emailing with mysql query Post 302821853 by Just Ice on Saturday 15th of June 2013 06:16:42 PM
Old 06-15-2013
try this one ... btw, i am testing this on ksh on solaris 10 ... works fine here ...
Code:
ADMemails="acme@gmail.com"
HCSemails="acme@gmail.com"
ADMSubject="Email to group status - Sent"
HCSSubject="Email to group status - Sent"
CHECKER='mysql -u root --password=123456 smsd -e "SELECT ID, SenderNumber, TextDecoded FROM inbox ORDER BY ReceivingDateTime DESC LIMIT 1  \G" |egrep -w 'ADM|BS|HC|IRC|IT|PTM|HCS' 2> /dev/null'

echo $CHECKER | grep ADM > /dev/null
if [ $? -eq 0 ]
then
	message="send email to ADM"
	for address in $ADMemails
        do
	      echo -e $message | mail -s $ADMSubject $address
	done
	echo " email sent to ADM contacts"
fi

echo $CHECKER | grep HCS > /dev/null
if [ $? -eq 0 ]
then
	message="send email to HCS"
	for address in $HCSemails
        do
	      echo -e $message | mail -s $HCSSubject $address
	done
	echo " email sent to PTM contacts"
fi

 

8 More Discussions You Might Find Interesting

1. Programming

How to query one to many mysql

Hi there, I have a hierarchical database that include 4 tables. Table A is the parent of B, B is Parent of C, C is parent of D. If I want to query everything in D that is associated with A.name, how do I do that? Thanks! YanYan (0 Replies)
Discussion started by: pinkgladiator
0 Replies

2. Shell Programming and Scripting

mysql help : query with 2 conditionals

Hi there, I have a table that stores multiple records for many different servers, each of which is timestamped ... I wanted to write a query that would enable me to only output the "latest" record (based on timestamp) for each "unique" server. So for example my main table looks like this ... (3 Replies)
Discussion started by: hcclnoodles
3 Replies

3. Web Development

mysql query help

hello all i have 2 columns every column in the following format column1 2011-04-01 11:39:54 column2 2019-02-03 00:00:00 i want get difference between above data as following 2 days 11:39 how to do so ? i tried many functions but nothing works please advice what is the query... (6 Replies)
Discussion started by: mogabr
6 Replies

4. Shell Programming and Scripting

mysql query in shellscript

Hi, I want to access mysql query from database , for that i have tried the below code #! /bin/bash TABLE_NAME=database1 USER_NAME=root IP_ADDR=111.20.9.256 somevar=`echo "select altid from alert where altid='2724'"| mysql -h $IP_ADDR -u $USER_NAME $TABLE_NAME ` echo $somevar ... (1 Reply)
Discussion started by: aish11
1 Replies

5. Programming

mysql query help

Hello i have created mysql query to compare to values and get difference in percentage as following: SELECT file_name, 100 - ((100 * (SELECT file_count FROM xipi_files z WHERE x.file_group = z.file_group AND x.file_name = z.file_name AND z.insert_date = CURDATE( ) - INTERVAL 1 DAY)) /... (1 Reply)
Discussion started by: mogabr
1 Replies

6. Shell Programming and Scripting

Conditional bash/mysql query help

I think(hope) I've got a simple one - I just need to send an email if a mysql query returns any results (ideally - it will never match). Currently I just pipe the mysql query output to the mail program, but of course that emails regardless of the output( and I check this every 10 minutes from... (5 Replies)
Discussion started by: jcass78
5 Replies

7. Shell Programming and Scripting

Need help on conditional emailing

Hi All, The following databse table maintains VENDOR and EMAIL details. VENOR_NAME VENDOR_EMAIL DELL surendra@dell.com HP rajkamal@hp.com ACER sumathi@acer.com NOKIA kunal@nokia.com SONY sinu@sony.com We have to find emaild id of a vendor based... (7 Replies)
Discussion started by: ROCK_PLSQL
7 Replies

8. Programming

Need help in mysql query

Hi All, i have a table in mysql with the following data Table name Test Assettype Serial_No Status location Mouse 123456 In Stock chennai Mouse 98765 Allocated chennai Keyboard ... (2 Replies)
Discussion started by: venkitesh
2 Replies
Log::Handler::Output::Email(3pm)			User Contributed Perl Documentation			  Log::Handler::Output::Email(3pm)

NAME
Log::Handler::Output::Email - Log messages as email (via Net::SMTP). SYNOPSIS
use Log::Handler::Output::Email; my $email = Log::Handler::Output::Email->new( host => "mx.bar.example", hello => "EHLO my.domain.example", timeout => 120, debug => 0, from => 'bar@foo.example', to => 'foo@bar.example', subject => "your subject", buffer => 0 ); $email->log(message => $message); DESCRIPTION
With this output module it's possible to log messages via email and it used Net::SMTP to do it. The date for the email is generated with "Email::Date::format_date". Net::SMTP is from Graham Barr and it does it's job very well. METHODS
new() Call "new()" to create a new Log::Handler::Output::Email object. The following opts are possible: host With this option you has to define the SMTP host to connect to. host => "mx.host.com" # or host => [ "mx.host.example", "mx.host-backup.example" ] hello Identify yourself with a HELO. The default is set to "EHLO BELO". timeout With this option you can set the maximum time in seconds to wait for a response from the SMTP server. The default is set to 120 seconds. from The sender address (MAIL FROM). to The receipient address (RCPT TO). Additional options are cc and bcc. subject The subject of the mail. The default subject is "Log message from $progname". buffer This opts exists only for security. The thing is that it would be very bad if something wents wrong in your program and hundreds of mails would be send. For this reason you can set a buffer to take care. With the buffer you can set the maximum size of the buffer in lines. If you set buffer => 10 then 10 messages would be buffered. Set "buffer" to 0 if you want to disable the buffer. The default buffer size is set to 20. debug With this option it's possible to enable debugging. The information can be intercepted with $SIG{__WARN__}. log() Call "log()" if you want to log a message as email. If you set a buffer size then the message will be pushed into the buffer first. Example: $email->log(message => "this message will be mailed"); If you pass the level then its placed into the subject: $email->log(message => "foo", level => "INFO"); $email->log(message => "bar", level => "ERROR"); $email->log(message => "baz", level => "DEBUG"); The lowest level is used: Subject: ERROR: ... You can pass the level with "Log::Handler" by setting message_pattern => '%L' flush() Call "flush()" if you want to flush the buffered lines. sendmail() Call "sendmail()" if you want to send an email. The difference to "log()" is that the message won't be buffered. validate() Validate a configuration. reload() Reload with a new configuration. errstr() This function returns the last error message. DESTROY
"DESTROY" is defined and called "flush()". PREREQUISITES
Carp Email::Date Net::SMTP Params::Validate EXPORTS
No exports. REPORT BUGS
Please report all bugs to <jschulz.cpan(at)bloonix.de>. If you send me a mail then add Log::Handler into the subject. AUTHOR
Jonny Schulz <jschulz.cpan(at)bloonix.de>. COPYRIGHT
Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-11-21 Log::Handler::Output::Email(3pm)
All times are GMT -4. The time now is 04:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy