Script to reset ownership of virtualmin email users

6 posts / 0 new
Last post
#1 Fri, 06/29/2012 - 16:52
austinfwd

Script to reset ownership of virtualmin email users

Had a little issue today. Wrote a script to fix it. I don't think the script is bullet-proof & may not always work on 100% of your users. But generally speaking, I feel like it's pretty solid. The only issue I foresee is when people customize the home directory path to be different from the domain admin username, etc.

Anyway, here it is. Hopefully it helps someone in the future (if you accidentally change ownership on some of your users) causing them to no longer have access to their email boxes:


#!/bin/bash

echo First we are setting the ownership on the parent accounts \(domains\)
for username in `grep /home/ /etc/passwd | grep -v /homes/ | awk -F: '{ print $1 }'`
do
echo Resetting ownership for: $username
useraccount=`grep ^\`echo $username\`: /etc/passwd`
homedir=`echo $useraccount | awk -F: '{ print $6 }'`
echo Home dir is: $homedir
echo Changing ownership of home directory recursively
chown -R $username:$username $homedir
echo Done.
echo .
done
echo .

echo Now we are setting the ownership on the child accounts \(email users\)
for username in `grep /home/ /etc/passwd | grep /homes/ | awk -F: '{ print $1 }'`
do
echo Resetting ownership for: $username
useraccount=`grep ^\`echo $username\`: /etc/passwd`
homedir=`echo $useraccount | awk -F: '{ print $6 }'`
echo Home dir is: $homedir
echo Changing ownership of home directory recursively
chown -R $username $homedir
echo Done.
echo .
done

By the way. I tried using virtualmin's built-in "Fix Permissions" in the "Validate Virtual Servers" section. But it doesn't appear to traverse to the individual mailboxes of the users in the domains. It seems to just fix the permissions & ownership for the website-related directories.

Fri, 06/29/2012 - 17:12
austinfwd

Sorry that the code is jacked up. It seems the forum was parsing the backticks when using the code tags and the result was that the script above didn't appear the way it should have.

Thu, 04/18/2013 - 16:16
SkaFan

it would be really nice if someone cloud fix this script.

Thu, 04/18/2013 - 17:46
andreychek

You can reset directory/file permissions by going into Limits and Validation -> Validate Virtual Servers -> Fix Permissions.

-Eric

Fri, 04/19/2013 - 05:08
SkaFan

no, that does not work, i tried it today.

edit: don't know who fixed the script, but thank you very much - works great!

Thu, 06/05/2014 - 15:47
silverark

The Virtualmin script wasn't working for me either so I used the scripts above. It's brilliant.

I have lots of sub-servers each with their own email accounts and unique suffixes per domain so I can have an info@ for each subserver. That's probably why the Virtualmin script isn't working.

Topic locked