I'm not having any success getting the below line to run in Cron. I've added / before % due to it being a special character. It works without the / when run directly from Terminal.

Eventually I'd like to run a recording from 11pm to 7am so am open to better suggestions. OS is Ubuntu Mint on an R-Pi3 Class10 32GB SD.

0 0 * * * arecord -f cd -d 60 -t wav | lame --preset 56 -mm - `date +/%Y/%m/%d/%H/%M`.mp3

Solution code:

0 0 * * * arecord -f cd -d 60 -t wav | lame --preset 56 -mm - /home/andy/`date +\%Y\%m\%d\%H\%M`.mp3

1 Answer 1


The cron escape character for % is \% (backslash), not /% (forward slash). As stated in the manual page for crontab(5) (man 5 crontab):

Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.

You likely meant to write:

0 0 * * * arecord -f cd -d 60 -t wav | lame --preset 56 -mm - `date +\%Y\%m\%d\%H\%M`.mp3

The convention of \ being used for escaping is used in many programming languages, too, such as C (and its descendants). Cron also adopts this convention.

  • 1
    Rookie error on my part - thanks. Unfortunately that still dd not output anything. I've got it working with -mm - /home/andy/date +\%Y\%m\%d\%H\%M.mp3 thanks again. Jan 11, 2018 at 17:53
  • 1
    Looks like the comment formatting mangled the command you posted, but glad to hear this pointed you in the right direction. You can always post that line of code as your own answer and accept that, or try posting the comment again (you'll need to escape the ` by writing \`), if you think that'd be useful to anyone in future.
    – Aurora0001
    Jan 11, 2018 at 17:57
  • I've just noticed the missing grave accent in my comment. The solution has been added to the question but credit to yourself for perseverance. Jan 11, 2018 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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