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!
* * * * * 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.
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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With