OS X Maintenance Shell Script

I felt the need to share this…

Firstly credit to Thorsten Rhau for writing this simple script.

Link – http://rhau.se/2009/01/26/a-simple-mac-os-x-maintenance-shell-script/#more-29

I’ve been looking for a script like this for some time now and thought about writing my own but havent found the time. Google-Fu to the rescue and there was Thorsten’s Post.

So here is his post….

I, like so many of my fellow Macintosh users want to keep my OS X installation well maintained. So i sat down and read a few man pages describing those nifty cli utilities that are included in OS X. Since OS X is a UNIX style operating system I decided to create a small shell script to perform the following maintenance tasks for me .

Repair Filesystem Permissions
Verify Disks
Run Periodic (cron) jobs
Update Prebindings
Verify Preference Files
Displa Cache size
Clear Cache

If you find the script interesting and want to use it on your mac you need to perform a few simple steps:

1. Copy the script to a text editor. I prefer vi or TextEdit.app.
2. Save the file. I will use the file name “MaintainMyMac.sh” during the rest of this description.
3. Make the file executable. To do that start Terminal.app and type chmod +x <path to MaintainMyMac.sh>
4. Now you can run the shell cript. E.g. ./MaintainMyMac.sh

I hope that you find this script as useful as I do.

You will be using this script at your own risk. I will not be responsible for loss of data, dogs, cats, keys or anything else.


Delete Offline Files Cache Windows 7

In Windows 7 there is no user interface to delete Offline Files cache (CSC cache).  The only way to delete cache is using registry key. Detail steps are given below.

  • Open Registry editor (Execute Regedit from Run window)
  • Traverse to the path path:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Csc\Parameters 
  • If Parameters key does not exist under CSC you can create a new node with that name.
  • Now in the Parameters node create a new registry value with the name FormatDatabase of typeREG_DWORD (i.e DWord 32-bit value)
  • Set the data in this new registry value to 1.
  • Close registry editor.
  • Reboot the machine

The above steps can only be done from an administrator’s account. We can do the above steps from command line too. For this you just need to run the below command from elevated administrator command prompt.

reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Csc\Parameters /v FormatDatabase /t REG_DWORD /d 1 /f 

If you run the above command from a normal administrator command prompt you will get “Error: Access is denied” message.

Note that the ‘Delete temporary files’ button under the ‘Disk Usage’ tab in  ‘Manage Offline files’ window is not meant for deleting offline files cache. Some people have the misconception that this deletes offline files cache. This is not true.

Back up your gmail in Linux

So for a long time I’ve been thinking about archiving my Gmail account as i have been a customer of Google’s since around 2004. Recently Gmail had a bit of a blackout and i worried that the interwebs apocalypse was upon us. It really made me think what if when the service returns my mail is missing. In truth my life is in that ickle 10.9GB mailbox and I of all people didn’t have a backup. I spend my life telling others to backup, backup, backup!!!!.

Anyway with a little bit of help from Matt Cutts wonderful blog i was able to implement a simple backup. Here is a link to the blog post…. http://www.mattcutts.com/blog/backup-gmail-in-linux-with-getmail/  Matt is a Software Engineer at Google and currently heads up the Webspam team. Anyway enough on Matt… For your convenience i have copied Matt’s post below for you to read but i don’t take any credit for the work.

How to back up your Gmail on Linux in four easy steps by Matt Cutts.

I really like Gmail, but I also like having backups of my data just in case. Here’s how to use a simple program called getmail on Unix to backup your Gmail or Google Apps email. We’ll break this into four steps.

Step 0: Why getmail?

If you browse around on the web, you’ll find several options to help you download and backup your email. Here are a few:

Step 1: Install getmail

On Ubuntu 7.10 (Gutsy Gibbon), you would type

sudo apt-get install getmail4

at a terminal window. Hey, that wasn’t so bad, right? If you use a different flavor of Linux, you can download getmail and install it with a few commands like this:

cd /tmp
[Note: wget the tarball download link found at http://pyropus.ca/software/getmail/#download ]
tar xzvf getmail*.tar.gz
cd (the directory that was created)
sudo python setup.py install

Step 2: Configure Gmail and getmail

First, turn on POP in your Gmail account. Because you want a copy of all your mail, I recommend that you choose the “Enable POP for all mail” option. On the “When messages are accessed with POP” option, I would choose “Keep Gmail’s copy in the Inbox” so that Gmail still keeps your email after you back up your email.

For this example, let’s assume that your username is bob@gmail.com and your password is bobpassword. Let’s also assume that you want to back up your email into a directory called gmail-archive and that your home directory is located at /home/bob/.

I have to describe a little about how mail is stored in Unix. There are a couple well-known methods to store email: mbox and Maildir. When mail is stored in mbox format, all your mail is concatenated together in one huge file. In the Maildir format, each email is stored in a separate file. Needless to say, each method has different strengths and weaknesses. For the time being, let’s assume that you want your email in one big file (the mbox format) and work through an example.

Example with mbox format

– Make a directory called “.getmail” in your home directory with the command “mkdir ~/.getmail”. This directory will store your configuration data and the debugging logs that getmail generates.
– Make a directory called gmail-archive with the command “mkdir ~/gmail-archive”. This directory will store your email.
– Make a file ~/.getmail/getmail.gmail and put the following text in it:

type = SimplePOP3SSLRetriever
server = pop.gmail.com
username = bob@gmail.com
password = bobpassword

type = Mboxrd
path = ~/gmail-archive/gmail-backup.mbox

# print messages about each action (verbose = 2)
# Other options:
# 0 prints only warnings and errors
# 1 prints messages about retrieving and deleting messages only
verbose = 2
message_log = ~/.getmail/gmail.log

Added: Run the command “touch ~/gmail-archive/gmail-backup.mbox” . If you change the path in the file above, touch whatever filename you used. This command creates an empty file that getmail can then append to.

The file format should be pretty self-explanatory. You’re telling getmail to fetch your email from pop.gmail.com via a POP3 connection over SSL (which prevents people from seeing your email as it passes between Gmail and your computer). The [destination] section tells where to save your email, and in what format. The “Mboxrd” is a flavor of the mbox format — read this page on mbox formats if you’re really interested. Finally, we set options so that getmail generates a verbose log file that will help in case there are any snags.

Example with Maildir format

Suppose you prefer Maildir instead? You’d still run “mkdir ~/.getmail” and “mkdir ~/gmail-archive”. But the Maildir format uses three directories (tmp, new, and cur). We need to make those directories, so type “mkdir ~/gmail-archive/tmp ~/gmail-archive/new ~/gmail-archive/cur” as well. In addition, change the [destination] section to say

type = Maildir
path = ~/gmail-archive/

Otherwise your configuration file is the same.

Step 3: Run getmail

The good news is that step 2 was the hard part. Run getmail with a command like “getmail -r /home/bob/.getmail/getmail.gmail” (use the path to the config file that you made in Step 2). With any luck, you’ll see something like

getmail version 4.6.5
Copyright (C) 1998-2006 Charles Cazabon. Licensed under the GNU GPL version 2.
msg 1/99 (7619 bytes) from <info@example.com> delivered to Mboxrd /home/bob/gmail-archive/gmail-backup.mbox
msg 2/99 (6634 bytes) from <sales@example.com> delivered to Mboxrd /home/bob/gmail-archive/gmail-backup.mbox

99 messages retrieved, 0 skipped
Retrieved 99 messages from SimplePOP3SSLRetriever:bob@gmail.com@pop.gmail.com:995

Hooray! It works! But wait — I have over 99 messages, you say. Why did it only download 99 messages? The short answer is that Gmail will only let you down a few hundred emails at a time. You can repeat the command (let getmail finish each time before you run it again) until all of your email is downloaded.

Step 4: Download new email automatically

A backup is a snapshot of your email at one point in time, but it’s even better if you download and save new email automatically. (This step will also come in handy if you have a ton of Gmail and don’t want to run the command from Step 3 over and over again for hours to download all your mail.)

We’re going to make a simple cron job that runs periodically to download new email and preserve it. First, make a very short file called /home/bob/fetch-email.sh and put the following text in the file:

# Note: -q means fetch quietly so that this program is silent
/usr/bin/getmail -q -r /home/bob/.getmail/getmail.gmail

Make sure that the file is readable/executable with the command “chmod u+rx /home/bob/fetch-email.sh”. If you want to make sure the program works, run the command “/home/bob/fetch-email.sh”. The program should execute without generating any output, but if there’s new email waiting for you it will be downloaded. This script needs to be silent or else you’ll get warnings when you run the script using cron.

Now type the command “crontab -e” and add the following entry to your crontab:

# Every 10 minutes (at 7 minutes past the hour), fetch my email
7,17,27,37,47,57 * * * * /home/bob/fetch-email.sh

This crontab entry tells cron “Every 10 minutes, run the script fetch-email.sh”. If you wanted to check less often (maybe once an hour), change “7,17,27,37,47,57″ to “7″ and the cron job will run at 7 minutes after every hour. That’s it — you’re done! Enjoy the feeling of having a Gmail backup in case your net connection goes down.

Bonus info: Back up in both mail formats at once!

As I mentioned, mbox and Maildir have different advantages. The mbox format is convenient because you only need to keep track of one file, but editing/deleting email from that huge file is a pain. And when one program is trying to write new email while another program is trying to edit the file, things can sometimes go wrong unless both programs are careful. Maildir is more robust, but it chews through inodes because each email is a separate file. It also can be harder to process Maildir files with regular Unix command-line tools, just because there are so many email files.

Why not archive your email in both formats just to be safe? The getmail program can easily support this. Just change your [destination] information to look like this:

type = MultiDestination
destinations = (‘[mboxrd-destination]‘, ‘[maildir-destination]‘)

type = Mboxrd
path = ~/gmail-archive/gmail-backup.mbox

type = Maildir
path = ~/gmail-archive/

Note that you’ll still have to run all the “mkdir” commands to make the “gmail-archive” directory, as well as the tmp, new, and cur directories under the gmail-archive directory.

Bonus reading!

What, you’re still here? Okay, if you’re still reading, here’s a few pointers you might be interested in:
– The main getmail site includes a page with lots of getmail examples of configuration files. The getmail website has a ton of great documentation, too. Major props to Charles Cazabon for his getmail program.
– This write-up from about a year ago covers how to back up Gmail as well.
– The author of getmail seems to hang out quite a bit on this getmail mailing list. See the main site for directions on signing up for the list.
– If you’re interested in a more powerful setup (e.g. using Gmail + getmail + procmail), this is a useful page.
– For the truly sadistic, learn the difference between a Mail User Agent (MUA) and a Mail Transfer Agent (MTA) and how email really gets delivered in Unix.
– I’ve been meaning to write all this down for months. Jeff Atwood’s recent post finally pushed me over the edge. Jeff describes a program that offers to “archive your Gmail” for $29.95, but when you give the program your username/password it secretly mails your username/password to the program’s creator. That’s pretty much pure evil in my book. And the G-Archiver program isn’t even needed! Because Gmail will export your email for free using POP or IMAP, it’s not hard to archive your Gmail. So I wrote up how I back up my Gmail in case it helps anyone else. Enjoy!

Added March 16, 2008: Several people have added helpful comments. One of my favorites led me to a post by commenter Peng about how to back up Gmail with IMAP using getmail. Peng describes how to back up the email by label as well. He mentions that you could use the search “after:2007/1/1 before:2007/3/31″ and assign the label FY07Q1 to the search results, for example. Then you can back up that single label/mailbox by making the getmail config file look like this:

type = SimpleIMAPSSLRetriever
server = imap.gmail.com
username = username
password = password
mailboxes = (“FY07Q1″,)

type = Mboxrd
path = ~/.getmail/gmail-backup-FY07Q1.mbox

Peng also mentions a nice bonus: since you’re backing up via IMAP instead of POP, there’s no download limit. That means that you don’t have to run the getmail program repeatedly. Thanks for mentioning that Peng!

Windows 7 boots to black screen with cursor only

Sometimes this is caused by a virus that changes the permissions of your System32 folder. here is a fix for that.

  1. Keep tapping F8 at boot time in order to boot into Repair Mode.
  2. Open a Command Prompt.
  3. Identify the drive letter for your System drive. It is usually C: but it could be D: or E:. It won’t be X:. I will call it Q: for the purpose of this exercise.
  4. Type the following commands and press Enter after each. Make sure to type them accurately – do not take any liberties!
    path  %path%;Q:\Windows\System32
    cacls  Q:\Windows\System32  /E  /T  /C  /G everyone:F
    (this command will probably take a long time to run)
  5. Reboot normally. If your problem was caused by inappropriate permissions then Windows should now work.
  6. Click Start.
  7. Type the three letters cmd into the Search box.
  8. Press Ctrl+Shift+Enter
  9. Click “Run as Administrator”.
  10. Type the following commands and press Enter after each of them:
    cacls  C:\Windows\System32  /E  /T  /C  /G  System:F  Administrators:R
    cacls  C:\Windows\System32  /E  /T  /C  /G  everyone:R

If the above doesnt work it may be that the whole of your C drives permissions were changed if so replace the following line in point 4

cacls  Q:\Windows\System32  /E  /T  /C  /G everyone:F


icacls C:\ /Grant Everyone:(F)

Restoring Registry Files manually from Command Prompt

You can restore your registry files manually to an earlier point by going through the steps outlined below. The process is involved and requires some careful typing. Ask a computer-savvy friend to assist you if you lack experience in this area.
1. Keep tapping F8 during the early boot phase.
2. Select Safe Mode Command Prompt from the menu.
3. Log on as Administrator if prompted.
4. Select Repair when prompted.
5. Select the Command Prompt.
6. Identify the correct drive letter for your Windows installation. It could be drive E: or F:. You do it by typing the commands
dir C:\Win*
dir D:\Win*
dir E:\Win*
until you find the Windows folder.
I will call that drive “Q:”.
7. Type these commands:
cd /d Q:\windows\System32\config
xcopy *.* Q:\RegBack\
cd RegBack
8. Examine the dates of the Software, System and SAM files. Were the files created before or after your problem became apparent?
9. If they were made before the problem became apparent then you can type these commands:
copy /y software  ..
copy /y System  ..
copy /y Sam ..
(the two dots are part of each command)
10. Reboot normally. If things do not work out then you can backtrack by copying the original registry files from Q:\Regback to Q:\Windows\System32\config.

CS50 – Instructions – If you need to resize your hard drive space in Appliance 19

I added my rather huge dropbox folder to the Appliance and found that the hard drive space wasnt enough so found the following instuctions on a forum and wanted to share in case anyone else needed to do this.

Issue: I’m out of disk space on my root partition. Solution: The root partition is created on a logical volume with LVM2. Just add another disk, extend the volume group, and then extend the logical volume.

(indented from the terminal)

Added new physical partition /dev/sda3 create a physical volume out of it

 pvcreate /dev/sda3

Now, add it to the volume group that my logical volume is on

vgextend VolGroup00 /dev/sda3

Now that the volume group has more disk space, the logical volume can grow

lvextend -L+11G /dev/mapper/fedora-root

Ok, last of all, I want to filesystem to recognize that more space is available

fsadm resize /dev/mapper/fedora-root

sweet, I have more space now

df -h

Anyway i hope it helps someone else.

Now accepting Bitcoins…


I can now accept bitcoin payments for my services.

Just let me know before hand that you want to pay by bitcoin.

Comments Disabled

Evening all.

Had to disable comments as 280 spam comments a day is enough to send me around the bend. If you have something to say email me or pop up on twitter and connect with me and lets talk properly.

Four Very Very short links…. Wednesday 10th April 2013

So yesterday saw me miss my normal blog post of four short links, i was incredibly busy yesterday and today looks to be the same but i have a small window of opportunity to post a quick note on here. so here it is.

Four very short links that I think are worth a quick read for your day.

Sorry again its short and sweet without my little thoughts but have a look….

Wait! Don’t sell your Xbox 360! Xbox 720 unlikely to be backwards compatible

Vudu Headquarters Robbed, Hard Drives With Private Customer Data Stolen

Facebook Home Review: Surrender Yourself Unto Zuck

Windows XP given its twelve-month notice

Four Short Links…. Monday 8th April 2013

Morning all,

Todays Four short links.

Guy Kawasaki – social media guru, entrepreneur, innovator and venture capitalist. Gives away four books.

So browsing through my Google Plus feed yesterday I noticed Guy Kawasaki’s post about his free books and decided to take a look, one in particular caught my attention because I’m a novice at Google Plus really. His awesome book called ‘What the Plus!” Google + for the rest of us is a guide to Google plus with some extraordinary nuggets of info gold in there. I haven’t looked at the other books yet but they are The Macintosh Way, Database 101 and Computer Curmudgeon. Go grab them no doubt full of great knowledge.

Ask Aaron Lee – 7 Steps To Follow If Your Twitter Account is Suspended

So this is nothing new. But it is currently helping me with one of my clients who have their twitter accounts suspended for no good reason. This Blog post was written just over three years ago and judging by the comments its still helping people today. :-) great work Aaron. If you have had your Twitter account suspended suddenly you can use these methods to try and get your account back up and running, providing you have been following the rules.

The Twin Cities Maker – Raspberry Pi Powered Cat Feeder

For all your Cat loving Geeks out there this is a must. Make your own cat feeder because getting out of your den is hard enough, and its fun right! Using the raspberry Pi to feed your cat is just genius. The more Pi Projects I see I continue to be amazed at what they come up with and this one is a good one.

Sophos, Naked Security – Ransomware scares victims with child sex abuse images

So I get called all the time for Ransomware removal a lot, but really it has turned very vile recently with this new version. This new version as reported by Sophos’s Naked Security Team shows images purporting to be the sexual abuse of children. Saying that the machine has been used for the purposes of viewing child pornography. This lock screen shows images of Children supposedly aged as young as 13 years old. At the moment there is no way to tell if these images are of Children or what age they are but this kind or ransomeware has turned really sinister and will no doubt frighten some individuals into not getting in touch with Computer techs like myself because of the fear of arrest for something they did not do. And I wonder if it would also make them more likely to pay the “online fine” Scary thoughts indeed.