Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > OS X

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 11, 2008, 01:22 AM   #1
iCeFuSiOn
macrumors 6502a
 
Join Date: Jul 2007
Mac OS X 10.5 Leopard Maintenance Script

If you're having any problems with your Mac and you are using Mac OS X 10.5, then you're in luck. I've taken the time to write a shell script that you can execute via Terminal which will allow you to perform any of the following tasks:
  • Run maintenance scripts (daily, weekly, and monthly).
  • Flush user cache and user-level log files.
  • Flush global cache (/Library/Cache)
  • Flush system cache (/System/Library/Cache)
  • Check for corrupted preference files (user and global)
  • Flush Directory Service cache
  • Flush Apple Type Server (ATS) -- useful if you have corrupted font problems.
  • Update application prebinding
  • Verify disk integrity
  • Repair permissions on boot volume.

This is for all of you who don't feel like installing a third party program like Onyx to do the dirty work.

I've attached the file in a .ZIP to this post, just extract and run it from Terminal. All clean-up options are selectable so you don't have to run the same ones every time you run the script.

NOTE: As with any maintenance tasks, you should always have a recent backup on hand just in case for whatever reason something happens.

For those of you who are interested, here's the code:

Code:
#! /bin/bash

#	=====================================================
#	* Mac OS X Maintenance Script						*
#	* Written by Kristan M. Kenney (iCeFuSiOn)		    *
#	* Last modified on February 11, 2008 4:47:18 AM AST *
#	* Revision 1.0.1b									*
#	* For use on Mac OS X 10.5 "Leopard" Only!			*
#	* I AM NOT RESPONSIBLE IF YOU DO SOMETHING WRONG!   *
#   =====================================================

clear
echo "Mac OS X 10.5 Maintenance Script"
echo "WARNING: Close any running applications before continuing."
echo ""
echo -n "Would you like to proceed? (y/N): "; read PROCEED
if [ -z $PROCEED ] || [ "$PROCEED" = "n" ] || [ "$PROCEED" = "N" ]; then
  exit 0
fi
echo ""
echo -n "Run maintenance cron scripts (daily, weekly, and monthly)? (Y/n): "; read CRONSCR
if [ -z $CRONSCR ] || [ "$CRONSCR" = "y" ] || [ "$CRONSCR" = "Y" ]; then
	sudo periodic daily weekly monthly
	echo "Maintenance scripts have run successfully."
	echo ""
fi
echo ""
echo -n "Flush user cache and log entries? (Y/n): "; read USRLOG
if [ -z $USRLOG ] || [ "$USRLOG" = "y" ] || [ "$USRLOG" = "Y" ]; then
	echo "Flushing saved logs under current users Home directory ..."
	cd ~/Library/Logs
	sudo rm -rf ~/Library/Logs/*

	echo "Flushing user cache ..."
	rm -rf ~/Library/Safari/Downloads.plist
	cd ~/Library/Caches
	sudo rm -rf ~/Library/Caches/*
fi
echo ""
echo -n "Flush global cache? (Y/n): "; read GLOBAL_CACHE
if [ -z $GLOBAL_CACHE ] || [ "$GLOBAL_CACHE" = "y" ] || [ "$GLOBAL_CACHE" = "Y" ]; then
	echo "Flushing global cache ..."
	cd /Library/Caches
	sudo rm -rf /Library/Caches/*
fi
echo ""
echo -n "Flush system cache? (Y/n): "; read SYS_CACHE
if [ -z $SYS_CACHE ] || [ "$SYS_CACHE" = "y" ] || [ "$SYS_CACHE" = "Y" ]; then
	echo "Flushing system cache ..."
	cd /System/Library/Caches
	sudo rm -rf /System/Library/Caches/*
fi
echo ""
echo -n "Check for corrupted preference files on your computer? (Y/n): "; read PREF_INTEGRITY
if [ -z $PREF_INTEGRITY ] || [ "$PREF_INTEGRITY" = "y" ] || [ "$PREF_INTEGRITY" = "Y" ]; then

	echo "Checking for corrupted or damaged preference files,"
	echo "any errors will be reported here ..."

	echo "* User preferences ..."
		cd ~/Library/Preferences
		plutil -s *.plist
		
	echo "* Global preferences ..."
		cd /Library/Preferences
		plutil -s *.plist
fi
echo ""
echo -n "Flush Directory Service cache? (Y/n): "; read DSERVCACHE
if [ -z $DSERVCACHE ] || [ "$DSERVCACHE" = "y" ] || [ "$DSERVCACHE" = "Y" ]; then
	echo "Flushing Directory Service resolver cache ..."
	dscacheutil -flushcache
fi
echo ""
echo -n "Flush LaunchServices database (fixes duplicate Open With entries, etc) (Y/n):"; read LS_DATABASE
if [ -z $LS_DATABASE ] || [ "$LS_DATABASE" = "y" ] || [ "$LS_DATABASE" = "Y" ]; then
	echo "Flushing LaunchServices database ..."
	/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user 
fi
echo ""
echo -n "Flush Apple Type Server (ATS) cache? (Y/n): "; read AppleATS_CACHE
if [ -z $AppleATS_CACHE ] || [ "$AppleATS_CACHE" = "y" ] || [ "$AppleATS_CACHE" = "Y" ]; then
	echo "Flushing Apple Type Services font cache ..."
	sudo rm -rf `lsof | grep com.apple.ATS/annex.aux \
	| grep Finder | cut -c 66-139`
	sudo rm -rf /private/var/folders/*/*/-Caches-/com.apple.ATS
fi
echo ""
echo -n "Update application prebinding? (Y/n): "; read APP_PREBIND
if [ -z $APP_PREBIND ] || [ "$APP_PREBIND" = "y" ] || [ "$APP_PREBIND" = "Y" ]; then
	echo "Updating application prebinding (dyld cache) ..."
	sudo update_prebinding -root / -force
fi
echo ""
echo -n "Enable logging for verification process (y/N): "; read LOG_VERIFICATION
if [ -z $LOG_VERIFICATION ] || [ "$LOG_VERIFICATION" = "n" ] || [ "$LOG_VERIFICATION" = "N" ]; then
	echo "Verifying disk integrity and repairing disk permissions ..."
	echo "Please note, this may take several minutes."
	sudo diskutil rerpairVolume /
	sudo diskutil repairPermissions /
else 
	echo "Verifying disk integrity and repairing disk permissions ..."
	echo "Please note, this may take several minutes."
	sudo diskutil rerpairVolume / > ~/Library/Logs/maintenance_script.log
	sudo diskutil repairPermissions / > ~/Library/Logs/maintenance_script.log
fi
echo ""

# All done! We can go ahead and restart the computer now.
echo "Maintenance tasks have completed."
echo "If you have performed system level tasks, please restart now."
echo "Otherwise, please log out and back in."
You can save the above code in a TextEdit document, just ensure you save it with an extension of .sh for the sake of simplicity. To make it executable, open Terminal, navigate to the location of the document, and run:

Code:
chmod a+x [filename].sh
I've fully tested this on 10.5.1 and there are no adverse effects or anything like that. Hope this helps, have a good day everyone!
Attached Files
File Type: zip maintenance_script.zip (2.0 KB, 934 views)
__________________
iCeFuSiOn
Switched to Apple on 01/15/2008!
15" MacBook Pro 2.2 GHz
8 GB iPod touch

Last edited by iCeFuSiOn; Feb 11, 2008 at 02:51 AM.
iCeFuSiOn is offline   0 Reply With Quote
Old Feb 11, 2008, 02:00 AM   #2
mrflip
macrumors newbie
 
Join Date: Jul 2007
If you run
Code:
	cd ~/Library/Logs
	sudo rm -rf *
and for whatever reason ~/Library/Logs didn't exist, you would suddenly become unhappy according to the formula
unhappiness = importance of location when you launched this script / recency of last backup.
consider instead
Code:
	cd ~/Library/Logs && sudo rm -rf ~/Library/Logs/*
and maybe even do a (ls -lR | head ; printf "\n...\n<snip>\n...\n\n" ; ls -lR | tail) and then ask the user to confirm.

Honestly though -- like the WuTang clan, sudo rm -rf * is nothing to f' with. Be very careful running something like this from a script.
mrflip is offline   0 Reply With Quote
Old Feb 11, 2008, 02:11 AM   #3
SaSaSushi
macrumors 68030
 
SaSaSushi's Avatar
 
Join Date: Aug 2007
Location: Takamatsu, Japan
Quote:
Originally Posted by iCeFuSiOn View Post
If you're having any problems with your Mac and you are using Mac OS X 10.5, then you're in luck. I've taken the time to write a shell script that you can execute via Terminal which will allow you to perform any of the following tasks:
  • Run maintenance scripts (daily, weekly, and monthly).
  • Flush user cache and user-level log files.
  • Flush global cache (/Library/Cache)
  • Flush system cache (/System/Library/Cache)
  • Check for corrupted preference files (user and global)
  • Flush Directory Service cache
  • Flush Apple Type Server (ATS) -- useful if you have corrupted font problems.
  • Update application prebinding
  • Verify disk integrity
  • Repair permissions on boot volume.
This is for all of you who don't feel like installing a third party program like Onyx to do the dirty work.
Thank you very much but doesn't this already exist?:

Maintenance Automator Script
__________________
27" Late 2013 iMac i7 GTX780M 32GB/1TB Fusion
32GB iPhone 5s | 32GB iPad 3 LTE
16GB iPad 2 3G | Canon EOS 450D
SaSaSushi is offline   0 Reply With Quote
Old Feb 11, 2008, 02:52 AM   #4
iCeFuSiOn
Thread Starter
macrumors 6502a
 
Join Date: Jul 2007
Quote:
Originally Posted by mrflip View Post
If you run
Code:
	cd ~/Library/Logs
	sudo rm -rf *
and for whatever reason ~/Library/Logs didn't exist, you would suddenly become unhappy according to the formula
unhappiness = importance of location when you launched this script / recency of last backup.
consider instead
Code:
	cd ~/Library/Logs && sudo rm -rf ~/Library/Logs/*
and maybe even do a (ls -lR | head ; printf "\n...\n<snip>\n...\n\n" ; ls -lR | tail) and then ask the user to confirm.

Honestly though -- like the WuTang clan, sudo rm -rf * is nothing to f' with. Be very careful running something like this from a script.
mrflip: Thank you for pointing this out to me. I've been used to writing Windows CMD script files now for a while so this one was new to me. I've gone ahead and made the change in the script, let me know if it's any better.
__________________
iCeFuSiOn
Switched to Apple on 01/15/2008!
15" MacBook Pro 2.2 GHz
8 GB iPod touch
iCeFuSiOn is offline   0 Reply With Quote
Old Mar 7, 2008, 05:37 PM   #5
rezzo
macrumors regular
 
Join Date: Jun 2006
Location: Chile
thanks for the script!
rezzo is offline   0 Reply With Quote
Old Mar 7, 2008, 06:02 PM   #6
scotty588
macrumors 6502
 
Join Date: Jan 2007
Location: Carlsbad, CA
I use an app called MainMenu
scotty588 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > OS X

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Apple script batch shell script prramesh Mac Programming 5 Sep 15, 2013 03:35 AM
How to best perform maintenance on a Mac to increase performance cap2587 Mac Basics and Help 3 May 28, 2013 12:46 PM
first script/autamator script feed back zyr123 Mac Programming 1 Jul 17, 2012 10:00 AM
Mac Pro 3.1 Thermal compound maintenance bax2003 Mac Pro 1 Jul 5, 2012 11:55 AM

Forum Jump

All times are GMT -5. The time now is 06:26 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC