Articles July 9, 2007 at 2:16 am

Elmer: Automated Deletion of Mobile ( Portable ) Accounts.

Clean up your PHDs and remove the trailer park of mobile homes you have lying around.

If you run a lab that uses mobile accounts , one of the problems that probably you deal with is the rabbit droppings effect: where users create accounts in the local netinfo database on your lab machines by virtue of logging in. Not only are their accounts cached locally but normally some part of the home directory as well. The normal reason for deploying such an environment is bandwidth concerns with using network accounts. You may re-image your lab enough that the effect is minimal but if your on say a quarterly system chances are these accounts are accumulating exponentially.

<code>&lt;p&gt;Elmer is a script that runs at shutdown and will delete user accounts that have not logged in&amp;nbsp;&amp;nbsp;( with a loginhook )&amp;nbsp;after a configurable&amp;nbsp;number of days . The rationale being that users must synch their information to the server for it to be backed up and these cached copies are just taking up space, and&amp;nbsp;potentially&amp;nbsp;causeing syncs to take longer due to&amp;nbsp;comparisons. This is my first public release of this script so I have&amp;nbsp;endeavored&amp;nbsp;to make sure all is in order,but as always if you have any code&amp;nbsp;additions , bug reports please leave them in the comments or&amp;nbsp;&lt;a href="http://blog.irisink.com/zack/index.html"&gt;contact me&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You &amp;nbsp;can download the Package Project -&amp;gt;&lt;a href="http://blog.irisink.com/files/scripts/elmersrc.dmg"&gt;here&lt;/a&gt;&amp;lt;- and a pre-built Package -&amp;gt;&lt;a href="http://blog.irisink.com/files/scripts/elmer.dmg"&gt;here&lt;/a&gt;&amp;lt;-&amp;nbsp;&lt;/p&gt;

&lt;p&gt;The following is the version 1 of included readme doc: &amp;nbsp;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Elmer "Rabbit Droppings" remover v1.9&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;These scripts are designed to remove mobile home directories after 15 days&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;test in a non production environment before deploying!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;This installer package will install (by default) into /Library/Application Support/Wallcity.&lt;/p&gt;

&lt;p&gt;It then runs a postflight script that adds a loginhook and sym links the main script (elmer) to /etc/rc.shutdown.local, which runs at shutdown.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: That the postflight will not overwrite an existing script so you may call it at the last active line of your existing hook.&amp;nbsp;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;bash '/Library/Application Support/Wallcity/loginhook' &amp;#36;1&lt;/p&gt;

&lt;p&gt;Or alternatively you could also use:&lt;/p&gt;

&lt;p&gt;exec '/Library/Application Support/Wallcity/loginhook' &amp;#36;1&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;loginhook:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;This script creates(touches) a file in mobile home directories called ".logintime", each time the user logs in the file's modification time is updated. By default non-mobile local accounts, network users and admin users are excluded from the file creation process, but this is configurable.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;elmer&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;This script is the payload, working off the files created by the loginhook, this script searches the top directories in the configured home path (/Users) and then finds all touch files that have not been modified in the last 15 days (configurable.)&amp;nbsp;It verifies that the user is not an admin and is indeed a mobile user(authenticationauthority). It double checks to make sure that the path we are about to delete is in fact the uses home directory (NFSHomeDirectory). As the user it attempts to recursively remove all the contents of the home directory , it then removes the empty directory as root ( or moves out of the way in error)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: You should exclude ".logintime" from syncing.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&amp;nbsp;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Note: This script was designed to run at shutdown, if you would like to run as a cron job then you might have it touch /etc/nologin or check that no one if logged in to the console before you start.&lt;/p&gt;

&lt;p&gt;In the future more updated&amp;nbsp;information&amp;nbsp;will be&amp;nbsp;available&amp;nbsp;at my companies &lt;a href="http://blog.irisink.com/"&gt;blog&lt;/a&gt;&lt;/p&gt;
</code>

Leave a reply

You must be logged in to post a comment.