Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 612
Richard Deurwaarder Avatar asked Sep 12 '26 18:09

Richard Deurwaarder


1 Answers

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

like image 195
Richard Deurwaarder Avatar answered Sep 16 '26 12:09

Richard Deurwaarder