FirstClown

firstclown at firstclown.us

Archive for February 14th, 2005

New GeekTool Script: Database Checker

This, of course, goes hand in hand with the Web Server Checker, but is a little more targeted. Just because your web server is up, doesn't mean your database is. I learned this the hard way. (I still love you anyway, HE).

The main thing here is to know what kind of database your hosting provider is running and then install the client for it. Hurricane Electric runs MySQL, but I'll cover PostgreSQL here too since I use it at work. So first install the Mac client for MySQL or PostgreSQL, depending on what you have. I'll wait.

Now we'll want to set up a script just like the one we did for the Web Site Checker. All the same options apply. For the command, however, we'll use one of the following:

  • MySQL:

    /usr/local/bin/mysql -u username -p passwd -h hostname.us -e "select 1+1;"

    Where username and passwd is your username and password to log into the database (May not be the same as to log into your web server. Check your information on this.) and hostname.us is the hostname of the server.

  • PostgreSQL:

    Ah, PostgreSQL. They like to make things supra complicated. Due to security concerns (They send the password in clear text mind you. How more secure can you get!) they don't allow you to specify a password on the command line. Instead, all you get are hoops.

    From here, what you basically need to do is create a file in your home directory called .pgpass, chmod it to 600, and have one line in it that is hostname:port:database:username:password. Better yet, just do *:*:*:username:password. That'll show 'em.

    Then set the command to:


    /usr/local/bin/psql -U username -h hostname.us -c "select 1+1;"

    Where username is the user name to connect to the database and hostname.us is the hostname of the server. Sometimes PostgreSQL requires you to specify the name of the database you need to connect to. Just put that after the -c "select 1+1;". This depends on how your host has it set up.

NOTE: Test the command in a Terminal window first to see if it works or not. You may need to tweak the above examples to get it to work with your host. Then copy and paste it into the command text field in GeekTool.

This'll send the command "Add one plus one" and if your database server can't do that, you've got problems. The script will show the little fail icon if there is any kind of error; connection error or database error. Name it something like "Web Site Database" and put it up next to your Web Server Checker. They make beautiful music together.

Security Warning: Don't do this on a computer you don't have control over. You'll be putting your precious database password in clear text on the machine, and if anyone can waltz in and get physical access to this machine, they will have your password and login to your database. Fair warning. I, personally, will only do this on my desktop machine at home.

FirstClown is powered by WordPress
Entries (RSS) and Comments (RSS).