4

Why do I get this error

/bin/sh: 1: Syntax error: Unterminated quoted string

when calling this in /etc/crontab?

19 2 * * *   root    for f in $(cat /home/rubo77/list); do date +"%y-%m-%d %T">"$f".datefile; done

The list only contains paths to existing directories and those are the first lines in my crontab:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

When I call the for commandline on the console in bash I get no errors

rubo77
  • 27,777
  • 43
  • 130
  • 199
  • 2
    You need to escape the `%` signs - see this related question: [How can I execute `date` inside of a cron tab job?](https://unix.stackexchange.com/questions/29578/how-can-i-execute-date-inside-of-a-cron-tab-job) – steeldriver Apr 11 '20 at 00:31

1 Answers1

5

You need to escape the % signs

see this related question: How can I execute `date` inside of a cron tab job?

You can use this to fix it

sed -i 's/%/\\%/g' /etc/crontab
rubo77
  • 27,777
  • 43
  • 130
  • 199