Archive for the ‘Uncategorized’ Category

cURL strange behaviour

Friday, February 13th, 2009

This night I was struggling with cURL (directy from the CLI and mod_curl from php). I was trying to get the Content-Length of a static file to determine it’s filesize but I never saw the result on some objects.

poisonbook:data poison$ curl -I http://iscsi06/v/tt/001/123/1123081.jpg -H "Host: de.video.netlogstatic.com"
HTTP/1.1 200 OK
Expires: Sat, 14 Mar 2009 23:56:18 GMT
Cache-Control: max-age=2592000
Content-Type: image/jpeg
Accept-Ranges: bytes
Last-Modified: Wed, 06 Feb 2008 11:16:08 GMT
Date: Thu, 12 Feb 2009 23:56:18 GMT
Server: lighttpd/1.4.19

As you see, no Content-Length header in it. So I was thinking it’s a bug in lightty and I started to browse the forums. After a half an hour reading, testing, cursing and drinking beers I finally tried to do a manual HTTP request using telnet.

poisonbook:data poison$ telnet iscsi06 80
Trying 192.168.44.6...
Connected to iscsi06.
Escape character is '^]'.
GET /v/tt/001/123/1123081.jpg HTTP/1.1
Host: de.video.netlogstatic.com

HTTP/1.1 200 OK
Expires: Sat, 14 Mar 2009 23:57:00 GMT
Cache-Control: max-age=2592000
Content-Type: image/jpeg
Accept-Ranges: bytes
Last-Modified: Wed, 06 Feb 2008 11:16:08 GMT
Content-Length: 0
Date: Thu, 12 Feb 2009 23:57:00 GMT
Server: lighttpd/1.4.19

You can see, there IS a Content-Length header, but when it’s 0 cURL just ignores it!

Remember: Content-Length: 0 is as good as non-existant in cURL

The versions of cURL I used:

CLI: curl 7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3 AND curl 7.15.5 (x86_64-pc-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8c zlib/1.2.3 libidn/0.6.5

PHP:     [version] => 7.15.5, [host] => x86_64-pc-linux-gnu, [ssl_version] =>  OpenSSL/0.9.8c, [libz_version] => 1.2.3

Cheers,
Nicolas

iTerm and applescript

Thursday, January 15th, 2009

At Netlog (the company I work for) we have thousands of servers. Fortunately, every server has a logical name (eg.: web001, web002, web003, …).

From time to time, some monkeywork has to be done on a bunch of those servers. Although we have very nice tools for this, sometimes you just have to logon the box and type some commands manually. iTerm, my favourite terminal program on OSX, has a nice feature for doing this: “Send input to all tabs”. The hardest part is to open a new window with all the tabs and ssh’ing to the servers themselves. Once you have an ssh session in every tab you enable to send the input to all tabs and you’re done :)

Suppose:

You have 10 hosts: host01, host02, …, host10 and you want to execute the command ‘df -h’ (view the disk usage).
What you can do is open iTerm, create 10 tabs (press ‘command-t’ 10 times) and type in each tab: ’ssh host0x’ where x is the box you want to connect to.
Once you’re connected to each box, simply press ‘command-shift-i’ or choose “Send input to all tabs” and pick your favourite host.
Execute your command and when you browse through all the tabs, you’ll see the info of each server. Nice isn’t it? :)

“Hey, this is stupid, why are you blogging about this?”

Well, the annoying part is the establishing of the ssh connection itself. I really got sick of it and I was thinking if I could get the tab ID, I could do something like ’ssh host${TABID} ‘, send this to all my tabs and got logged in automatically. I wrote a very small applescript to do this.

tell application "iTerm"
	activate
	set format to "" & (choose from list {"0", "00", "000"} with prompt "Choose the format")
	set num to text returned of (display dialog "Enter the offset (default: 1)" default answer "1")
	-- Get the current terminal
	set myTerminal to current terminal
	-- Make a list of all the sessions (tabs) in this terminal (window) to iterate over
	set SessionList to sessions of myTerminal
	repeat with mySession in SessionList
		tell mySession
			set formatText to text -(count format) thru -1 of (format & num)
			write text "" & formatText
		end tell
		set num to num + 1
	end repeat
end tell

I was really amazed by the ease of applescript. It took me 20 minutes to write and debug this (being completely new to applescript).
The biggest help for me was the MacScripter site and in particular the posts of Craig Smith.

Although the chance that this snippet is useful for anybody except me is small, it’s a nice way to demonstrate how easy it is to automate something with applescript.

Cheers,
Nicolas

A new start for 2009

Thursday, January 15th, 2009

Hi all,

I know this blog has been inactive for a long time, but one of my intentions for 2009 is to maintain it again. It takes some time but I’m willing to devote one hour in the week for this. I hope I can persist :)

Cheers,

Nicolas