Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The following works as expected from the command prompt. But it does not work from cron.

mysqldumpslow <(tail -1000 `mysqladmin variables \
    | grep slow_query_log_file | awk '{print $4}'`) \
    | mail -s "slow log from `hostname` sorted by time" shantanu.oak`hostname` \
    > /root/slow_succ.txt 2> /root/slow_err.txt

I get the following error:

/bin/sh: -c: line 0: syntax error near unexpected token `('

Do certain characters need to be escaped in cron? Or is it an issue with subshell in cron?

share|improve this question
Duplicate of… ? – Hubbitus Oct 8 '15 at 13:08
up vote 10 down vote accepted

I'll expand on what SvenW said by stating that I would put this command into a script for two reasons:

  1. It avoids any issues with escaping characters in crontab.
  2. It allows you to clearly indicate to your fellow administrators what the job does without wasting any of their cycles decrypting the one-liner magic you've created. Such as calling the script /root/bin/ You may not be in an environment with other administrators, but this will serve to remind you what the heck you were thinking a year from now! :)
share|improve this answer
Kudos for the "what the heck you were thinking a year from now!". – Tonny Mar 9 '12 at 12:14

The easiest solution for cron escaping problems: Put the command in it's own shell script and just call this script from cron.

share|improve this answer

The reason it does not work is that cron is not bash. Creating a subshell using brackets is part of the bash syntax. A clue to this is in the first "word" of error message.

Backticks would work to create a subshell except that you are already using backticks inside your subshell so you can't use those again.

As the others have already said, write a script and call that from cron.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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