Search code examples
croncarriage-return

crontab adding carriage returns


I'm using a script to add multiple cronjobs to users at the same time like so:

sed -e "s/\[\[USER\]\]/$user/g" $file > /home/deploy/cronjobScripts/tmp
crontab -u $user "/home/deploy/cronjobScripts/tmp"
crontab -u $user -l

$file points to a path with the template cronjob file.

But after crontab adds it to a user, it adds ^M to every line (carriage return in vim) which breaks the commands it has to execute.

Why does crontab do this and how can I prevent it?


Solution

  • Arkascha was right after all, it seems that \r\n was present but vim did not show it.

    When I used cat -vE /home/deploy/cronjobScripts/tmp it showed the \r after removing those with dos2unix the cronjobs worked perfectly