cron script to set proper gid in a user's home directory

I need a cron script to run every hour or so to go through a user’s (called “grb”) home directory (which other users work from) and reset all the gid (called “rg”) to the user (
“grb”).

Can I loop over other user’s gid and do something like

gid=riv
uid=eme
find /home/grb -group ${gid} -print | xargs chown ${uid}:rg
gid=…
uid=…
.
.
.

Or does anyone have a script like this already and is willing to share it?

If you are sharing via Samba you could use the force group directive on that share.

From what I read in your description the following would do it:

#!/bin/bash
chgrp -R rg /home/grb

This will change whatever the guid is to rg of /home/grb and everything below it.

I am not sure if you want only guid riv changed to rg (what your script does) or all guids (what I reead in your description).