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


FROMDATE=`date -d "last week 13:00 " '+%Y-%m-%d'`
TODATE=`date '+%Y-%m-%d'`
SUBJECT="Slow Query Report -- $TODATE"
EMAIL="[email protected]"

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

1 Answer 1


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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .