photo
Jordan Sissel
geek

Tue, 20 Apr 2004

dhclient and dhclient-exit-hooks

Using DHCP on resnet only gives me search rit.edu as far as search domains. So, I got bored and wrote a small script to add useful domains for me. This is done using a feature of ISC's dhcp program, dhclient, called dhclient-exit-hooks. This is a shell script that is run when dhclient finishes fetching you an IP address.
This will add csh.rit.edu and cs.rit.edu to the search line in my /etc/resolv.conf.
Requires: a version of sed that supports inline editing (the -i option)

#!/bin/sh

DOMAINS="csh.rit.edu cs.rit.edu"

for dom in $DOMAINS; do
        grep "^search.*\b$dom\b" /etc/resolv.conf > /dev/null 2>&1 || 
        sed -i -e "/^search/ s/$/ $dom/" /etc/resolv.conf
done

Comments: 0 (view comments)
Tags: , ,
Permalink: /geekery/109
posted at: 19:13

boredom in my SE class

I was curious to see how much slower sprintf was in perl than an equivalent print statement. Using Debug::Profile hotness, after a million calls it turns out that sprintf is insignificantly slower. Yay boredom.

time elapsed (wall):   47.2054
time running program:  34.0098  (72.05%)
time profiling (est.): 13.1956  (27.95%)
number of calls:       2000000

%Time    Sec.     #calls   sec/call  F  name
60.20   20.4722        0  20.472220  *  
21.04    7.1548  1000000   0.000007     main::sp
18.77    6.3828  1000000   0.000006     main::nosp

sub sp {
   return sprintf("(%s) %s - %s\n", $album, $artist, $title);
}

sub nosp {
   return "(" . $album . ") " . $artist . " - " . $title . "\n";
} 

Comments: 0 (view comments)
Tags:
Permalink: /geekery/108
posted at: 11:39

Search this site

Navigation

Metadata

Home About Resume My Code (SVN)

Articles

ARP Security Dynamic DNS with DHCP OpenLDAP+Kerberos+SASL PPP over SSH SSH Security: /bin/false Week of Unix Tools Work Efficiency

Projects

fex firefox tabsearch firefox urledit grok keynav liboverride newpsm (FreeBSD) nis2ldap pam_captcha poor man's backup Solaris audio utility xboxproxy xdotool xmlpresenter xpathtool misc scripts

Presentations

Yahoo! Hack Day '08 Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials SSH Tunneling (Video)

Tag Cloud

Calendar

< April 2004 >
SuMoTuWeThFrSa
     1 2 3
4 5 6 7 8 910
11121314151617
18192021222324
252627282930 

Friends

BarCamp Kent Brewster Tantek Çelik John Resig Wesley Shields Tyler Shields

Technorati