Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.