Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi there,
I am trying to do somehting similar, but on a wider scale.
I am trying to write a script that would open the home directory, open the first (of 650) user's folder
open the ?mail directory, which every user hasThen I need the script to read each of the files and folder names with one preceding directory and a carriage return as the delimiter.
Then the output is to be put into a file called .mailboxlist
cd /home
cd user1
cd mail
grep ls (this is where I am most stuck – adding the ‘mail/’ before each name and a carriage return as the delimiter) > .mailboxlist (??)
cp .mailboxlist /home/user1/.mailboxlist
The file “.mailboxlist” should look like this:
mail/Sent
mail/Trash
mail/Drafts
mail/tech support
mail/test1
After that is completed, I need the script to go to the next folder (user2) and do it again.Any help would be greatly appreciated.
Thanks,
Nett

I would probably use perl myself (but thats just because I like it!), something along the lines of:
perl -e 'foreach $user(`ls /home`){`ls -1 /home/$user/mail > /home/$user/.mailboxlist`}'I don't think that will prefix mail/ for each entry but it would be simple enough to put similar to the above into a script which opens a file and adds mail/ to each line before writing it....

for name in $(/bin/ls /home); do [[ -d /home/$name/mail ]] && for file in $(/bin/ls /home/$name/mail); do [[ -d /home/$name/mail/"$file" ]] && echo "mail/$file" >> /home/$name/.mailboxlist; done; done
( assuming it really should be "mail" rather than "Mail" )

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |