1

I have a number of zip files in a certain folder. I want to capture file name and the size of the files in a CSV format in day wise and put it in crontab so I can report on a daily basis, and then mail it in each report.

Files are in /somedirectory/archive/test:

-rw-rw-r--+ 1 AAAA AAAA 9.3M May  30 17:09 XXXXX_20140530_0401_28.txt.gz
-rw-rw-r--+ 1 AAAA AAAA 9.3M May  30 17:09 XXXXX_20140530_0401_29.txt.gz
-rw-rw-r--+ 1 AAAA AAAA 9.3M May  31 17:09 XXXXX_20140531_0401_01.txt.gz

Now I want to crate a cronjob to run everyday and capture the same CSV which we prepared in day wise.

example

test30052014.csv:

"XXXXX_20140530_0401_28.txt.gz", "9.3","May 30"
"XXXXX_20140530_0401_29.txt.gz", "9.3","May 30"

test31052014.csv:

"XXXXX_20140531_0401_01.txt.gz", "9.3","May 31"

And after generated the CSV file I should be able to send mail as well via crontab.

1 Answer 1

1

I will use :

find . -maxdepth 1 -type f -exec stat --format=\"%n\",%s,\"%y\" {} \;

and To email with attached CSV you can use :

find . -maxdepth 1 -type f -exec stat --format=\"%n\",%s,\"%y\" {} \; > output_$(date +%F).csv  && echo "PFA" | mail -s "subject" -a output_$(date +%F).csv

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .