0

I have a CentOS 7 with postfix.

E-mails are stored in:

Var/vmail/DomainName/Usernames/Maildir/.Junk/

The only variable is the Usernames that correspond to each mailbox.

I could use a script to count the files for each address junk folder and put them into a centralized text file.

What would be the simplest way to do this so that I can have an output like:

Username1: nn

Username2: nn

.............

Where nn is the number of files in the junk folder of the respective user.

2
  • can you post the output of ls -lrt Var/vmail/DomainName/Usernames/Maildir/.Junk Commented Oct 12, 2016 at 9:09
  • Using ls -lrt /var/vmail/vmail1/DomainName/Username1/Maildir/.Junk/new/ outputs: total 40 and lists permissions, dates and names of the 3 files that are in the junk/new/ folder. Commented Oct 12, 2016 at 9:19

1 Answer 1

0

this helps ?

#!/bin/bash for UserName in /var/vmail/DomainName/* do PATH="${UserName}/Maildir/.Junk" Num_Of_Files=$(find ${PATH} -type f | wc -l) echo "${UserName} : ${Num_Of_Files}" done 
6
  • line 8: find: command not found line 8: wc: command not found Commented Oct 12, 2016 at 9:24
  • replace find and wc with this /usr/bin/find /usr/bin/wc Commented Oct 12, 2016 at 9:27
  • Putting that to both find and wc worked, but now I get the main path doubled (and invalid path due to that). And a wierd " â" character at start and end of path. Fixed that, it was a lowercase at fault. Commented Oct 12, 2016 at 9:31
  • do we have sub direcotry inside the .Junk ? add -maxdepth 1 in the find command to scan only 1 level Commented Oct 12, 2016 at 9:38
  • No need for depth, it's fine now. However, do correct in your answer by removing /var/vmail/DomainName/ from the PATH=, or else the path will double (and I'll mark it as correct). Commented Oct 12, 2016 at 9:44

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.