Macbook Air Drive Clean up

I came across this need as I am currently managing several Macbook Air laptop carts in the school district I work for. As these labs get used by multiple users eventually I begin to see quite a few kids as they show up at my door with 100% disk space on the logon screens and a completely grey screen if they logon. Performance of these 64GB SSD drives is pretty nice, but after about 40 different users logon and save a few things (iMovie projects,etc) storage becomes an issue.  It has been a real pain to clean up since I could not logon to the machine either(Just a grey screen). Apple Remote Desktop(ARD) still seems to be working with these machines in this state so my first reaction was that I could send out the little one line UNIX ARD command that I use to clean the machines during the summer…

mkdir /Temp && mv /Users/admin/ /Temp && mv /Users/Shared/ /Temp && rm -rf /Users/* && mv /Temp/admin/ /Users && mv /Temp/Shared/ /Users && rm -rf /Temp && ls -la /Users
 

That works great to clean up the /User directories in the off months, but these kids need their work. So at first I was tediously going through the /Users/ directory by date like this: ls -lat /Users/
to figure out what I could delete and then outputting the same without the details: ls -t /Users/
Then I’d make a list of users and put them into a spreadsheet with one column of names and the other column with: rm -r /Users/
Once I finally had that I would do a find/replace in a text editor for the Tab character and finally putting the long list of commands into a Unix command in ARD like…

rm -r /Users/joe.shmoe
rm -r /Users/yougetthepoint
 

So after a little research and testing I came up with a solution that will dynamically delete home folders based on last folder activity.
To clean these up as root with an ARD unix command send this…

df -h
touch /Users
touch /Users/AdminAccountName
touch /Users/Shared
find /Users -maxdepth 1 -type d -mtime +15 -exec rm -r {} \;
df -h
 

That will show your current disk usage, update the time of the important folders in the /Users directory (so they are not deleted!) and delete any home folders older than 15 days. Modify the number of days as needed 🙂

This works find if you put it into a new Unix command like this…
MacbookAirCleanup

Example Output:
HostName (127.0.0.1)
Filesystem Size Used Avail Capacity Mounted on
/dev/disk0s2 56Gi 56Gi 0Bi 100% /
devfs 181Ki 181Ki 0Bi 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% /net
map auto_home 0Bi 0Bi 0Bi 100% /home
map -fstab 0Bi 0Bi 0Bi 100% /Network/Servers

Filesystem Size Used Avail Capacity Mounted on
/dev/disk0s2 56Gi 41Gi 14Gi 75% /
devfs 180Ki 180Ki 0Bi 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% /net
map auto_home 0Bi 0Bi 0Bi 100% /home
map -fstab 0Bi 0Bi 0Bi 100% /Network/Servers

I have tested this on 10.5 through 10.8.2 systems. Your mileage may vary and I claim no responsibility for what you might do with this script(Unless it is really cool 😉 )

Happy Cleaning!
Craig

References:

Thanks to this litte page for getting my started…
http://www.howtogeek.com/howto/ubuntu/delete-files-older-than-x-days-on-linux/

Advertisements

About Craig Szymanski

Systems Administrator Photography Enthusiast
This entry was posted in ARD, Macintosh, Network Administration and tagged , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s