Google Analytics API via cURL

I spend a lot of time in Google Analytics creating custom reports for various things. I usually start with Google Analytics Query Explorer to make sure I’m getting the right data before creating a script to pull in the data for the report.

Once I’ve got a good result set, I’ll use cygwin with cURL (and the script below) to grab the xml so I can see how Google actually returns it.

There’s nothing tricky about it & the comments should tell you everything you need to fill in / do. I do use date to get the last 30 days of data, but you can change that to match the range that makes sense for you.

USER_EMAIL="" #Insert your Google Account email address here
USER_PASS="" #Insert your password here
TABLE_ID="" #Insert your table ID here (ie ga:123456)
METRICS="ga:visits" #Required
DIMENSIONS="ga:source" #Optional
SEGMENT="" #Optional. Add to the query below if needed
FILTERS="" #Optional. Add to the query below if needed
SORT="-ga:visits" #Optional
START_DATE=$(date -d "-30 days" +%Y-%m-%d) #Required
END_DATE=$(date -d "-1 day" +%Y-%m-%d) #Required
#### Get Google Auth Token
googleAuth="$(curl \
-d Email=$USER_EMAIL \
-d Passwd=$USER_PASS \
-d accountType=GOOGLE \
-d source=curl-dataFeed-v2 \
-d service=analytics \
| awk /Auth=.*/)"
##### Send Token & Query to Google
curl -H "Authorization: GoogleLogin $googleAuth" -k \

This is based on code from ga-api-http-samples for API Version 2 by api.nickm on Dec 14, 2009. It used to be easy to find on the example libraries page, but has been removed for a while.

Aspire One Black Screen of Death – Part 2

Many things have changed since I wrote my original post on Aspire One Black Screen of Death way back on 01/28/2009. Macles site is no longer at Blogspot, so you can’t get the latest BIOS file download from there or read other user’s experiences & tips. However, judging from the amount of traffic this post still gets, and other sites with articles describing the same thing, there are still lots of Aspire One users who continue to have the same problem.

Acer now has a document ( that describes the procedure to use if you get the Black Screen of Death.

But, in the download for the latest BIOS version, they now include a program called “InsydeFlash.exe”. The readme.txt file has three simple steps:
1. Connect AC power
2. Clik InsydeFlash
3. Click “sure” to start flash BIOS.

If your Aspire One will boot into Windows, you can use InsydeFlash to update the BIOS without having to fool around with the FN + ESC key method. I used this version to update from 3308 to 3310 & it worked just fine.

So, you need to download the 3310 version of the BIOS from Acer at, unzip all the files, copy them to a flash drive and run InsydeFlash.

In case you can’t find it on Acer’s site I’ve put a copy here you can download: BIOS_Acer_3310_A_AOA110 & AOA150

Just a reminder; this BIOS file is only for the Aspire One AOA110 & AOA150 models. Don’t even try it on any other models!

Good luck!

If a file exists then do (something) in bash

If you need to determine in a file exists in a directory use the first example.

Credit to for a simple answer.

if [ -f path/to/file.txt ]
echo "file exists"

If you need to know if it does not exist use this:

if [ ! -f path/to/file.txt ]
echo "file does not exist"

I had a list of files in "your_files.txt" and needed to know if they were in a directory or not. Combining read lines in a text file with bash to loop thru the list of files I was looking for and the "if  [ -f file.txt ]" was a fast way to find out.

while read line
if [ -f path/to/$line ]
echo "$line exists"
echo "$line does not exist"
done < your_files.txt

My Raspberry Pi has arrived!

I’ve been (im)patiently waiting for my Raspberry Pi to show up since mid-March & can’t wait to get started playing with it.

My goal is use it as the controller for a compact NAS despite the potential bandwidth issues with USB drives as the media. I’ll probably do the first backups with the drive(s) connected to the source machines and Rsync the changes afterward, so I’m not too concerned about saturation. I could be wrong tho.

I also want to try Puppy for Raspberry Pi – search or browse thru the posts on Barry’s blog for updates on his builds. It’s an Alpha now and still has some issues. I’ll post a link to the image once it gets to the Release stage.

Rasbperry Pi Links

Raspberry Pi home
Links to Downloads, wiki, Forum, & FAQs are in the top nav. Very helpful and beginner-friendly community.

RPi Verified Peripherals at
Very good list of known working & problem hardware including SD cards, USB hubs, mice & keyboards, plus some cases.

MagPi – A Magazine For Raspberry Pi Users
Fun & interesting to read projects, code to try, etc for all ages & experience levels.

Puppy Linux on the Raspberry Pi at the Raspberry Pi Forum

Read lines in a text file with bash

In bash it’s very easy to read a text file line by line and do something to each line. I do this in cygwin a lot to parse logs and other large files.

Your input file needs to have unix-style line endings or bash will get very confused. This trips me up a lot when working on files created with a Windows program.

There are many other ways of doing for/next loops in bash, but this is simple, fast and easy for quick scripts.

#! /bin/bash
while read line
echo $line
done < your_file.txt

If you want/need to use a batch file to read lines look at Batch file to read a text file and perform actions