2

I am on Linux OS 2.1. Options like mailx or uuencode are not configured on these servers. My objective is to email the list of files (with date and time) from a directory which were updated within one day. I have managed to make a script which let's me do that but when I recieve the email, all the lines appear as one continuous output. There are no breaks in the output. Outlook ignores the line breaks. Now this list has to go to some big users and I can't ask them to fix the setting in outlook to ignore the line breaks. Can this be achieved from the script which I am using

This is the script that I am using.

!/bin/bash
dir=/path-to-dir
cd $dir
find . -maxdepth 1 -type f -mtime -1 -exec ls -lrth {} \;> /tmp/filelist
cat /tmp/filelist | awk -F/ '{print $1,$2}' |awk '{print $6,$7,$8,$10}' | mail -s "Today's Directory List" email@address.com

I am to send this directory list once a day, hence will set a cronjob task to execute the script. I even tried sending the file as attachment but uuencode is not confiugred on the server. Hence I am looking for help with this.

Thanks

devnull
  • 103,635
  • 29
  • 207
  • 208

3 Answers3

0

Your issue may be the end-of-line character difference between unix and windows. Try changing:

awk '{print $6,$7,$8,$10}'

To:

awk '{print $6,$7,$8,$10,"\r"}'

and see if that helps.

Brad Lanam
  • 5,024
  • 2
  • 16
  • 25
0

Add 2 extra spaces at the beginning of each line to trick Outlook into not removing line-breaks. You can do this easily in the last awk of the pipeline.

It's probably worth including the "\r", suggested in another answer, as well so that it has the CR-LF line terminator that Outlook probably expects.

Community
  • 1
  • 1
Emmet
  • 5,588
  • 22
  • 35
  • Sir, you are a genius. It worked. This helped me solve my issue http://stackoverflow.com/questions/2099471/add-a-prefix-string-to-beginning-of-each-line – user3542284 Apr 16 '14 at 21:44
0

So this is the final script which is working fine for me. Thanks to Emmet for suggesting the use of extra space in front to trick outlook.

!/bin/bash
dir=/path-to-dir
cd $dir
find . -maxdepth 1 -type f -mtime -1 -exec ls -lrth {} \;|awk -F/ '{print $1,$2}' | awk '{ print $6,$7,$8,$10,"\r" }'> /tmp/filelist
awk '$0="  "$0' /tmp/filelist > /tmp/list.txt
mail -s "Today's Directory List" email@address.com </tmp/list.txt

Thanks again everyone.

Nicolas Perraut
  • 605
  • 1
  • 8
  • 24