Archive for the ‘Ubuntu’ Category

Baseline Web Page Testing using Curl

Wednesday, October 17th, 2007

I wanted a way to compare the page load times of my website on the old server and on the new server where I’m moving it.

I found an easy way to do this is to use curl. I was inspired by this article, but I improve on it by providing examples that work!

Here are the steps to getting a nice tabular file that shows load time information across a series of URL’s. (Only tested on Ubuntu.)

First I installed curl:
sudo apt-get install curl

Next I made a file called test_config.txt. Here are the contents:

-A "Mozilla/4.0 (compatible; cURL 7.10.5-pre2; Linux 2.4.20)"
-L
-w @logformat.txt
-D headers.txt
-H "Pragma: no-cache"
-H "Cache-control: no-cache"
-H "Connection: close"

url="http://foo.com/"
url="http://foo.members.linode.com/"
url="http://foo.com/utility/Text_Diff"
url="http://foo.com/"
url="http://foo.members.linode.com/"
url="http://foo.com/utility/Text_Diff"

The inspiration article explains a bit about what’s going on here.

Next I made a file called logformat.txt which you can see is referenced in test_config.txt above. Here are the contents of that file:

\\n
%{url_effective}\\t%{http_code}\\t%{content_type}\\t%{time_total}\\t%{time_namelookup}\\t%{time_connect}\\t%{time_starttransfer}\\t%{size_download}\\n
\\n

Again the inspiration article explains a bit about what's going on with this.

Finally we're ready to run curl. The trick here is that curl insists on outputting the contents of the web pages along with the statistics we want so we pipe it through grep as so (I'm assuming you're in the directory with the files we just made.):

$ curl -K test_config.txt | grep -i -r "^http://.*$" >> final_output.txt

This whole command runs curl using our configuration files, passes the output to grep, which then pulls out only the lines starting with http:// and outputs that to the file final_output.txt.

Stop your SSH Session from Timing Out

Monday, October 8th, 2007

Have you ever left your SSH connection idle for a few minutes and come back to a message like this?

root@none:~ # Read from remote host 69.91.127.167: Connection reset by peer
Connection to 69.91.127.167 closed.

Here is my attempt to fix this (On Ubuntu client and server):

On the server computer:

Set your ClientAliveInterval to a low value like 100

First back up your file:
root@none:/etc/ssh # sudo cp sshd_config sshd_config.backup

Then go into the /etc/ssh/sshd_config file with your editor of choice and add the line:
ClientAliveInterval 100
if it’s not there. Or edit that line if it’s already there.

Save the file, and restart your SSH server:
root@none:/etc/ssh # sudo /etc/init.d/ssh restart

Then close the session.

On your local (client) computer:

Set your ServerAliveInterval to 100 also.

Make a backup:
sudo cp /etc/ssh/ssh_config /ssh_config.backup

Then go into the /etc/ssh/ssh_config file with your editor of choice and add the line:
ServerAliveInterval 100
if it’s not there. Or edit that line if it’s already there.

And restart your session to server.

Better Searches Using Google Custom Search Feature

Friday, September 7th, 2007

I made three new custom search engines to help readers research key issues mentioned on this site. Basically each one is limited to search only within the top 3-10 forums, blogs, and support pages for the topic.

These will save a lot of time since you can now do just one search, instead of having to search every forum every time you have a question.

Here they are. Let me know how they work. I’m also adding them to the Helpful Resources sidebar so you’ll always have an easy link to them.

  1. Ubuntu Search (Searching *.ubuntuforums.org, *.ubuntu.com/ )
  2. GoldMine Search (Searching *.frontrange.com, *.contactreview.net, *.castellcomputers.com, *.thegmblog.com)
  3. QuickBooks Search (Searching *.quickbooksgroups.com, *.intuit.com )

Let me know if you have more resources, or blogs I can add to any of these search engines.

How to Make a Beep Sound in Linux and a Fun Program that Uses it

Sunday, August 12th, 2007

I came across my first Python script using Tkinter tonight while looking through old files. It creates a big screen where you can click anywhere on it and it makes your computer beep. Your Y position controls the frequency and your X position controls the duration.

Well, I wanted to give it a run for old time’s sake, but alas:
ImportError: No module named winsound (On Linux)

So I looked up the problem and decided to go with the beep package installed by running:
sudo apt-get install beep

Then I updated my script to run on both Windows and Linux. Enjoy*:

#!usr/bin/env/python

from Tkinter import *

try:
    import winsound
except ImportError:
    import os
    def playsound(frequency,duration):
        #apt-get install beep
        os.system('beep -f %s -l %s' % (frequency,duration))
else:
    def playsound(frequency,duration):
        winsound.Beep(frequency,duration)

root = Tk()
def callback(event):
    print "clicked at", event.x, event.y
    frequency=event.y * 6
    duration=event.x/2
    print "Freq= ", frequency, "HZ"
    print "duration=",duration, "ms"
    print ""
    if (frequency < 32000) and (frequency>40):
        playsound(frequency,duration)

frame = Frame(root, width=1000, height=800)
frame.bind("<Button-1>", callback)
frame.pack()
#message=Label(frame)
root.mainloop()

* Or annoy those near you …

Python – How to Copy and Paste to the Clipboard in Linux

Friday, July 20th, 2007

If you’re on a Linux system, you can use the pyGTK library. It’s got a clipboard feature.

Here’s how to use it (code thanks to Thomas Lee):

import pygtk
pygtk.require('2.0')
import gtk

# get the clipboard
clipboard = gtk.clipboard_get()

# read the clipboard text data. you can also read image and
# rich text clipboard data with the
# wait_for_image and wait_for_rich_text methods.
text = clipboard.wait_for_text()

# set the clipboard text data
clipboard.set_text('Hello!')

# make our data available to other applications
clipboard.store()

Here is the gtk.clipboard documentation.

Another Alternative

An alternative to the GTK library is the Xsel command line program. It should work for any Linux (or Unix?) with X.

And this is how you would use it (at least according to these guys):

#Copy from the clipboard:
import os
s = popen('xsel').read()

#Paste to the clipboard:
import os
os.popen('xsel', 'wb').write(s)