Conditional emailing with mysql query


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Conditional emailing with mysql query
# 8  
Old 06-16-2013
You're getting all those command not found errors because the pipes in the egrep pattern occur outside a quoted string. The shell is interpreting them and searching for the executables that match what it considers command names.

Further, unless my sight is starting to fail completely, I see nothing but a garbled variable assignment to CHECKER. There is no command substitution, so even if everything were quoted correctly, mysql will never execute.

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 9  
Old 06-16-2013
Dear Alister, thanks for your repply.

variable assigned to CHECKER are right:

Code:
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'

the result are:

Code:
 TextDecoded: ADM test filter 19:38

But I'm confuse in bash scripting for conditional email with mysql.
# 10  
Old 06-17-2013
i was just looking at this again and not seeing the mysql comand output that you showed as an example ... it seems your issue is that your script does not run the mysql command like alister said though not because of your command ... it looks like you are using single quotes instead of backticks when setting the CHECKER variable ... i also added the error redirect to /dev/null so you see less errors ...

change this ...
Code:
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''

to this ...
Code:
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)

or this ...
Code:
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`

This User Gave Thanks to Just Ice For This Post:
# 11  
Old 06-17-2013
hmm.. now i understand what Alister said.

Thanks Just Ice. ok now I can run the code with:

Code:
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)

adding more knowledge to my brain. error redirect using /dev/null so I can see less errors Smilie

Thank you so much brother Just Ice and Alister for helping me.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

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

8. 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
Login or Register to Ask a Question