#!/bin/bash
# This shell script performs system maintenance tasks in OS X
# It has been verified on OS X 10.5
##### Declaring some functions
cacheSize()
{
SIZE=0
for a in `du -sk /Library/Caches/ \
/System/Library/Caches/ ~/Library/Caches/ | cut -f 1`
do
SIZE=`expr $SIZE + $a`
done
SIZEINMEGABYTE=`expr $SIZE \/ 1024`
echo "The Caches size is $SIZEINMEGABYTE MB"
}
clearCache()
{
cacheSize
echo -n "cleaning Caches ... "
sudo rm -r ~/Library/Caches/*
sudo rm -r /Library/Caches/*
sudo rm -r /System/Library/Caches/*
echo done
cacheSize
}
repairPermissions()
{
sudo diskutil repairPermissions / \
| grep -v "We are using special permissions for the file or directory" \
| grep -v "We are using a special gid for the file or directory"
# If you have more then one disk/partition please copy the code above
# and replace the "/" on the first line of code with the mount point of
# your partition / disk. Example: /Volumes/MyDisk
}
verifyDisks()
{
sudo diskutil verifyVolume /
# If you have more then one disk/partition please copy the code above
# and replace the "/" on the first line of code with the mount point of
# your partition / disk. Example: /Volumes/MyDisk
}
runPeriodic()
{
echo "running periodic jobs ... "
sudo periodic daily weekly monthly
echo done
}
updatePrebindings()
{
echo "updating prebinding information ... "
sudo update_prebinding -root /
echo done
}
verifyPreferenceFiles()
{
sudo plutil -s ~/Library/Preferences/*.plist
sudo plutil -s /Library/Preferences/*.plist
}
menu()
{
clear
echo "
1 Repair Filesystem Permissions
2 Verify Disks
3 Run Periodic (cron) jobs
4 Update Prebindings
5 Verify Preference Files
6 Displa Caches size
7 Clear Caches
8 All
q Quit MaintainMyMac
"
echo -n "Please enter your choice: "
read CHOICE
}
################################################################################
while true
do
menu
case $CHOICE in
1)
repairPermissions
echo ""
echo -n "Press ENTER to continue"
read
;;
2)
verifyDisks
echo ""
echo -n "Press ENTER to continue"
read
;;
3)
runPeriodic
echo ""
echo -n "Press ENTER to continue"
read
;;
4)
updatePrebindings
echo ""
echo -n "Press ENTER to continue"
read
;;
5)
verifyPreferenceFiles
echo ""
echo -n "Press ENTER to continue"
read
;;
6)
cacheSize
echo ""
echo -n "Press ENTER to continue"
read
;;
7)
clearCache
echo ""
echo -n "Press ENTER to continue"
read
;;
8)
verifyDisks
repairPermissions
verifyPreferenceFiles
runPeriodic
updatePrebindings
clearCache
echo ""
echo -n "Press ENTER to continue"
read
;;
q|Q)
exit 0
;;
*)
echo menu
;;
esac
done
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.