1

I have a Bash shell script which send an email in every day at certain time. the code is as follows:

first_dir=/test1 second_dir=/test2

[email protected]

allfiles=$(find /test1 /test2 -maxdepth 1 | sort) IFS=$'\n'

while true do sleep 24h

[ "$allfiles" != "" ] &&
    find $allfiles -maxdepth 1 -printf '%Tc\t%s\t%p\n' |
    mail -s "List Of All Files" "$email"

files="$allfiles"  

done 

This script is giving output in Single column. but I want the Output in two columns.

  • 1st column with files of first_dir=/test1
  • 2nd column with files of second_dir=/test2
2
  • 2
    First: you should use crontab for scheduling for a certain time. This will execute every 24h at the time the script is started. Commented Jan 22, 2014 at 11:28
  • @PeterMmm scheduling and running is not the issue. What i want is a clear list of files in the mail in two separate columns so that i can perform analysis easily Commented Jan 23, 2014 at 13:39

1 Answer 1

4

If you want them separated like that, don't join them together in the first place

first_dir=/test1
second_dir=/test2
while sleep 24h; do
    first_files=$(find $first_dir -maxdepth 1 -printf '%Tc\t%s\t%p\n')
    second_files=$(find $second_dir -maxdepth 1 -printf '%Tc\t%s\t%p\n')
    paste <(sort -t $'\t' -k 3,3 <<< "$first_files") \
          <(sort -t $'\t' -k 3,3 <<< "$second_files") |
    mail -s "List Of All Files" "$email"
done
Sign up to request clarification or add additional context in comments.

4 Comments

👍 This would be even better without the sleep and in a cron job.
YES I will use cron in that.
As mentioned earlier... the basic need/requirement is a clear list of files in two directories in one email.
You want to use | instead of \t? OK, then do it. It's that simple.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.