0
I have a strange problem when piping a cat to mail.
I have a simple text file which has been compiled from a script, which is a report on what folders were copied in the script. I then want to send this report via email to the system administrators.
The script generates the report just fine. When I run
cat /tmp/report.txt
I get nicely formatted output with all the line breaks I would expect.
Copy report. Started on Mon Sep 28 13:37:57 BST 2015
Run in progress?: Yes
3 directories were copied.
Copy started on 2015.09.28 at 13:37:57
Copying /mnt/smb/New folder (10) to /mnt/backup/New folder (10)
Copy completed on 2015.09.28 at 13:37:57
Copy info:
0.01user 0.47system 0:01.83elapsed 26%CPU (0avgtext+0avgdata 2668maxresident)k
0inputs+355896outputs (0major+150minor)pagefaults 0swaps
Copy started on 2015.09.28 at 13:37:59
Copying /mnt/smb/New folder (14) to /mnt/backup/New folder (14)
Copy completed on 2015.09.28 at 13:37:59
Copy info:
0.00user 0.41system 0:01.78elapsed 23%CPU (0avgtext+0avgdata 2620maxresident)k
0inputs+355896outputs (0major+152minor)pagefaults 0swaps
Copy started on 2015.09.28 at 13:38:01
Copying /mnt/smb/New folder (18) to /mnt/backup/New folder (18)
Copy completed on 2015.09.28 at 13:38:01
Copy info:
0.00user 0.28system 0:01.71elapsed 16%CPU (0avgtext+0avgdata 2768maxresident)k
0inputs+355896outputs (0major+151minor)pagefaults 0swaps
However, for some reason when I now pipe this to mail
cat /tmp/report.txt | mail -s "Copy Report" recipient@domain.com
or
mail -s "Copy Report" recipient@domain.com < /tmp/report.txt
This is the email I get.
Copy report. Started on Mon Sep 28 13:37:57 BST 2015
Run in progress?: Yes
3 directories were copied.
Copy started on 2015.09.28 at 13:37:57
Copying /mnt/smb/New folder (10) to /mnt/backup/New folder (10) Copy completed on 2015.09.28 at 13:37:57 Copy info:
0.01user 0.47system 0:01.83elapsed 26%CPU (0avgtext+0avgdata 2668maxresident)k
0inputs+355896outputs (0major+150minor)pagefaults 0swaps
Copy started on 2015.09.28 at 13:37:59
Copying /mnt/smb/New folder (14) to /mnt/backup/New folder (14) Copy completed on 2015.09.28 at 13:37:59 Copy info:
0.00user 0.41system 0:01.78elapsed 23%CPU (0avgtext+0avgdata 2620maxresident)k
0inputs+355896outputs (0major+152minor)pagefaults 0swaps
Copy started on 2015.09.28 at 13:38:01
Copying /mnt/smb/New folder (18) to /mnt/backup/New folder (18) Copy completed on 2015.09.28 at 13:38:01 Copy info:
0.00user 0.28system 0:01.71elapsed 16%CPU (0avgtext+0avgdata 2768maxresident)k
0inputs+355896outputs (0major+151minor)pagefaults 0swaps
What gives? Some line breaks are there, some aren't! I've tried editing the file in both vi and nano and ensured the line breaks were actually there. Also deleted them and made them again and the email output remains the same.
Using /usr/bin/mail
Further info:
I hand typed the following into a text file and did the same pipe to mail. I put the word "Copy" at the start of each line.
Copy started on 2015.09.28 at 13:37:57
Copying /mnt/smb/New folder (10) to /mnt/backup/New folder (10)
Copy completed on 2015.09.28 at 13:37:57
Copy info:
Copy 0.01user 0.47system 0:01.83elapsed 26%CPU (0avgtext+0avgdata 2668maxresident)k
Copy 0inputs+355896outputs (0major+150minor)pagefaults 0swaps
This is what I got in the email:
Copy started on 2015.09.28 at 13:37:57
Copying /mnt/smb/New folder (10) to /mnt/backup/New folder (10) Copy completed on 2015.09.28 at 13:37:57 Copy info:
0.01user 0.47system 0:01.83elapsed 26%CPU (0avgtext+0avgdata 2668maxresident)k
0inputs+355896outputs (0major+150minor)pagefaults 0swaps
I then removed all of the "Copy" words. This is what I got in the email.
Started on 2015.09.29 at 09:46:49
Copying /mnt/smb/New folder (10) to /mnt/backup/New folder (10) Completed on 2015.09.29 at 09:46:49
Info:
0.00user 0.46system 0:01.98elapsed 23%CPU (0avgtext+0avgdata 2552maxresident)k
0inputs+355896outputs (0major+149minor)pagefaults 0swaps
Thought it might be something to do with the word Copy but I've still got one line with no line break!
This is the output of cat -vet /tmp/report.txt
Copy report. Started on Mon Sep 28 13:37:57 BST 2015$
$
Run in progress?: Yes$
$
$
$
3 directories were copied.$
$
$
Copy started on 2015.09.28 at 13:37:57$
Copying /mnt/smb/New folder (10) to /mnt/backup/New folder (10)$
Copy completed on 2015.09.28 at 13:37:57$
Copy info:$
0.01user 0.47system 0:01.83elapsed 26%CPU (0avgtext+0avgdata 2668maxresident)k$
0inputs+355896outputs (0major+150minor)pagefaults 0swaps$
$
$
Copy started on 2015.09.28 at 13:37:59$
Copying /mnt/smb/New folder (14) to /mnt/backup/New folder (14)$
Copy completed on 2015.09.28 at 13:37:59$
Copy info:$
0.00user 0.41system 0:01.78elapsed 23%CPU (0avgtext+0avgdata 2620maxresident)k$
0inputs+355896outputs (0major+152minor)pagefaults 0swaps$
$
$
Copy started on 2015.09.28 at 13:38:01$
Copying /mnt/smb/New folder (18) to /mnt/backup/New folder (18)$
Copy completed on 2015.09.28 at 13:38:01$
Copy info:$
0.00user 0.28system 0:01.71elapsed 16%CPU (0avgtext+0avgdata 2768maxresident)k$
0inputs+355896outputs (0major+151minor)pagefaults 0swaps$
Are you using CRLF for line breaks in the email as per RFC 5322 section 2.1?
– Andrew Morton – 2015-09-29T17:32:57.247What linux version do you run? What version of /usr/bin/mail are you running? Is it a redirect to something else like Ubuntu has it redirected to hairloom-mailx? – ojs – 2015-09-29T18:17:12.113