Handling HTTP Redirection in Ruby

Zach Cutlip - - 2 mins read

I have a Ruby project where I’m dumping a bunch of bookmarks from delicious.com, then fetching each bookmarked page for analysis.

One of the problems I encountered early on is that the some of the web pages bookmarked would redirect to some other location. Simply checking for HTTP response code 200 was insufficient. I needed to check for redirection as well.

A quick Google search for “ruby follow http redirect” yields lots of results. Unfortunately, they’re all very similar, and not quite right. In general, the examples you come across (even the one in the official Ruby documentation) don’t handle the case when the redirected location is path relative to the original location. So you end up doing a get on a URL that looks like “../../redirected/location/index.html,” which clearly won’t work.

Mounting LVM Disks in Ubuntu

Zach Cutlip - - 1 min read

I always thought LVM (Linux’s Logical Volume Manager) was kind of neat for the flexibility it gives you in adding and removing disks and resizing volumes such. However, in practice, I find it’s usually more trouble than it’s worth. It adds a layer of complexity between me and my data.

Often I need to mount a disk configured with LVM on another Linux machine or in an Ubuntu live CD environment. Out of the box the logical volumes aren’t recognized, so I can’t mount them.

How to sudoedit non-interactively

Zach Cutlip - - 3 mins read

Okay, this one’s a bit esoteric, but I think it’s pretty cool. How do you use ‘sudoedit’ non-interactively such as from a script? Just a brief background about sudo: sudo is an authentication mechanism in Unix & Linux that allows unprivileged users to run specific commands (as defined by the system administrator) with root privileges without having the root password. This has several advantages over logging in as root:

  • Users can have specific, limited set of root privileges without having the entire set of root privileges.
  • Users use their own password, so the root password doesn’t have to be shared. If a user’s sudo privileges are revoked, the root password doesn’t have to be reset.
  • Each use of sudo is audited per user, so that each time sudo privileges are invoked, there is an event in the system logs that identifies the specific user and the command they ran.

Sudoedit is a command that is related to sudo. It lets users edit files that normally only root can edit, such as system configuration files. However instead of using “sudo” followed by the editing command, the user runs “sudoedit filename” and sudo invokes the user’s default editor, letting them edit the file.

The Shadow File

Zach Cutlip - - 1 min read

This is the first post to The Shadow File. I suppose a brief explanation is in order. What is The Shadow File? In Unix and Linux, an algorithm is used to create a one-way hash of a user’s password. This hash, along with the username and other information used to be stored in /etc/passwd. In many modern *nix systems, the password hash has been removed from the passwd file and is now stored in a separate file, because the passwd file is world-readable. This way, an attacker would have to obtain both files in order to attempt to recreate the password. The file that contains the password hashes is /etc/shadow. Now you know.