1

I have a very simple script that basically runs a command and then emails the report to a user:

#!/bin/bash

FROMDATE=`date -d "last week 13:00 " '+%Y-%m-%d'`
TODATE=`date '+%Y-%m-%d'`
SLOWLOG='/var/log/mysql/slow-queries.log'
REPORT='/home/user/slow.log.'$TODATE
PTQUERY='/usr/bin/pt-query-digest'
SUBJECT="Slow Query Report -- $TODATE"
EMAIL="blah@blah.com"



$PTQUERY --since=\'$FROMDATE\' --until=\'$TODATE\' $SLOWLOG > $REPORT


/usr/bin/mutt -s "$SUBJECT" "$EMAIL" < $REPORT

Everything works perfect when I run this manually (below)

/usr/bin/pt-query-digest --since='2015-10-21' --until='2015-10-28' /var/log/mysql/slow-queries.log > /home/user/slow.log

And if I echo the line in the script:

/usr/bin/pt-query-digest --since='2015-10-21' --until='2015-10-28' /var/log/mysql/slow-queries.log

When I run the script I get an error

Invalid --since value at /usr/bin/pt-query-digest line 13562.

So it looks like it could be something with the single quotes? I'm not sure. Any help would be greatly appreciated.

4

You're escaping the single quotes in the script, which means they don't get interpreted by the shell. That means that pt-query-digest gets the literal string '2015-10-21' rather than just the date, 2015-10-21. pt-query-digest presumably does not know what to do with the single quotes.

You should get rid of the escaped single quotes in --since=\'$FROMDATE\' and just use double quotes instead. Make sure to modify both uses in that line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.