Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubuntu 14.04 Cron outputs file names with ^M at the end

When I pipe output to a file in a cron job using the > operator, it always appends a ^M to the end of the file name. This shows up as a ? when I run ls in the directory but reveals itself as ^M when I edit the file in nano and go to save.

For example this command:

locale > locale.txt

Outputs a file named "locale.txt?" (i.e. "locale.txt^M")

I don't know why it does this, but I'm guessing it has something to do with environment variables. When I use > from a terminal it behaves properly. I've searched Google for this problem but apparently it doesn't like all these special characters in the query so I haven't found anything.

I've tried using mv to change the file name back to normal but it doesn't recognize the ? or the ^M character when I type in the file name.

I've seen that perhaps this is the carriage return "\r" character but I don't know why cron would put a Windows newline on the end of my file name. All help is appreciated. Thanks!

like image 741
Pat Avatar asked Aug 17 '15 15:08

Pat


People also ask

What is the use of * * * * * In cron?

* * * * * is a cron schedule expression wildcard, meaning your cron job should run every minute of every hour of every day of every month, each day of the week.

How do I read cron entries?

View Current Logged-In User's Crontab entries : To view your crontab entries type crontab -l from your unix account. View Root Crontab entries : Login as root user (su – root) and do crontab -l. To view crontab entries of other Linux users : Login to root and use -u {username} -l.

How do I see crontab logs?

Stop searching for logs On Ubuntu, Debian and related distributions, you will find cron jobs logs in /var/log/syslog . Your Syslog contains entries from many operating system components and it's helpful to grep to isolate cron-specific messages. You will likely require root/sudo privileges to access your Syslog.

What is cron daemon?

Cron is a daemon, a long-running process that only needs to be started once, and will run constantly in the background. Cron wakes up every minute, examines its list of things to do to see if any scheduled tasks need to be executed, and if so it executes them.


1 Answers

The problem is with the cron or script file itself: it has DOS line separators (CRLF) instead of Unix (LF only). You can fix it using dos2unix.

like image 67
Joni Avatar answered Sep 21 '22 03:09

Joni