Monday, 9 January 2017

bash - E-Mail Directory Listing in Linux

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

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...