[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: cron error - date command



Keith Bainbridge [2020-02-01T21:42:25+11] wrote:

> echo `date +%Y%b%d` >>   /home/keith/.bash_history

> I have this line as a cron-job, and constantly get error messages:
>
> /bin/bash: -c: line 0: unexpected EOF while looking for matching ``'
> /bin/bash: -c: line 1: syntax error: unexpected end of file
>
> and no output to .bash_history

The "%" character has a special meaning in crontab file. It is
interpreted as the end of line. The rest of the line will be sent to the
program as standard input stream. See crontab(5) manual:

    http://man7.org/linux/man-pages/man5/crontab.5.html

If you don't want this % effect you need to escape those characters with
backslash:

    echo `date +\%Y\%b\%d`

-- 
///  OpenPGP key: 4E1055DC84E9DFF613D78557719D69D324539450
//  https://keys.openpgp.org/search?q=tlikonen@iki.fi
/  https://keybase.io/tlikonen  https://github.com/tlikonen

Attachment: signature.asc
Description: PGP signature


Reply to: