[K12OSN] How about a scripting question :-)

Jim Kronebusch jim at winonacotter.org
Thu Nov 9 22:11:56 UTC 2006


> The last user in the group doesn't have a comma after their name to 
> be substituted w/ "@winonacotter.org OK". How about:
> 
> #!/bin/sh
> if [-f /etc/mailusers]; then rm -f /etc/mailusers; fi
> touch /etc/mailusers
> MAILUSERS=$(getent group staff | cut -d':' -f4 | sed 's/,/ /g')
> for EACH in $MAILUSERS; do
>   echo "$EACH at winonacotter.org OK" >> /etc/mailusers;
> done


Awesome....it works!  Here is the final result:

#!/bin/sh
rm -f /etc/mailusers
MAILUSERS=$(getent group staff | cut -d':' -f4 | sed 's/,/\n/g')
for EACH in $MAILUSERS; do
 echo "$EACH at winonacotter.org OK" >> /etc/mailusers;
done
postmap hash:/etc/mailusers

For some reason the "if [-f" for removal wasn't working, I got a "line 2: [-f:
command not found".  So for testing purposes I just dumped that portion for
simpler method.  Should the command just be "if [/etc/mailusers]; then rm -f
/etc/mailusers; fi"?

Anyhow when things weren't working I dumped the touch portion as well since I
didn't know what it did. I figured if the rm command ran, touch wouldn't be
able to find /etc/mailusers anyhow.  

Any suggestions to improve would be great, but for now, it works!

Thanks again to everyone.  This will make it very easy to keep our current
configuration and be able to remove students from our email offerings.  I will
now modify my Webmin Users and Groups module config and add the above script
into the "Command to run after making changes" field.  If the new user is
added to the "staff" group they will be added to the /etc/mailusers file, if
not they will just get file services.  I suppose I might have to add a
/etc/init.d/postfix/reload as well to read the new hash file.

-- 
This message has been scanned for viruses and
dangerous content by the Cotter Technology 
Department, and is believed to be clean.




More information about the K12OSN mailing list