I recently purchased a Dell C400 to play with various x86 Operating Systems. After mucking around with numerous Operating Systemts (Windows XP, OpenBSD, Ubuntu, OpenSolaris, Solaris 10 GA), I decided to convert my laptop to FreeBSD 6.0. Since I like to wander around my apartment with my laptop, I needed to get 802.11 wireless networking with WPA security working. After reading through the FreeBSD ifconfig and wpa_supplicant documentation, I learned that I needed to create a wpa_supplicant configuration file. After testing out a few configurations, I finally settled on the following configuration:
$ cat /etc/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant ctrl_interface_group=wheel
network={ ssid="SSID_OF_BASE_STATION” bssid=01:02:03:04:05:06 proto=WPA key_mgmt=WPA-PSK pairwise=TKIP group=TKIP scan_ssid=1 psk="THIS IS THE WPA PASSWORD YOU USE TO ACCESS YOUR NETWORK” }
Once the configuration file was in place, I manually started wpa_supplicant with the “-B” (daemonize), “-c config file,” and “-i wireless interface” options:
$ wpa_supplicant -B -i ath0 -c /etc/wpa_supplicant.conf
Once the daemon was working, I added a line to /etc/rc.conf to start wpa_supplicant when the system booted:
$ grep wpa_supplicant /etc/rc.conf
wpa_supplicant_enable="YES”
Everything is working now, and I am typing this from my wireless enabled FreeBSD laptop. Nice!
While reading some documentation today, I came across the libc isatty() and ttyname() functions. I was curious to see how they worked, so I decided to write a little test program:
$ cat tty.c
#include #include #include
int main(int argc, char**argv) { if ( argc != 2) { printf(“Usage: tty fdn”); exit(1); }
int fd = atoi(argv[1]);
if (isatty(fd)) { printf(“File descriptor %d is a terminal %sn”,fd, ttyname(fd)); } else { printf(“File descriptor %d is not a terminaln”,fd); }
exit(0); }
$ gcc -o tty tty.c
$ ./tty
Usage: tty fd
$ ./tty 0
File descriptor 0 is a terminal /dev/pts/4
$ ./tty 1
File descriptor 1 is a terminal /dev/pts/4
$ ./tty 4
File descriptor 4 is not a terminal
Even though this is a small meaningless program, programming in C is fun! Shibby!
While perusing the bash documentation today I came across the ${#} built-in, which can be used to view the size of a variable:
$ foo="some number of characters"
$ echo {#foo}
25
This could be useful for iterating through strings in a loop, and is now part of my shell programming crib notes. Niiiiiiiiiiiiiiiiice!
I first ran across smartmontools about a year ago, and like to install it on all of the systems I manage. This helps me understand the current health of the hard drives in the servers and desktops I manage, and allows me to predict when disk drives are about to fail (this of course assumes that declining attributes are good indicators). Since I am using FreeBSD 6.0 on my personal laptop, I wanted to get smartmontools and smartd working. This was easily accomplished by first installing the smartmontools package with the pkg_add utility:
$ pkg_get -r smartmontools
And secondly by adding a smartd_enable line to /etc/rc.conf to start the SMART daemon (smartd) at system boot time:
$ grep smartd /etc/rc.conf
smartd_enable="YES”
I really dig the FreeBSD ports tree.
I occassionally need to start bash more than once, and typically use exit (my .bash_profile is set to ignore ^D (EOF)) to leave the new version of bash. Periodically I hit exit one too many times, which causes my terminal session (and debugging sessions) to dissappear. Since this caused me a good deal of grief yesterday, I decided to find a fix in the bash documentation. After reading for 30-minutes or so, I came across the bash SHLVL variable:
$ echo SHLVL
1
$ bash
$ echo SHLVL
2
$ bash
$ echo SHLVL
3
$ exit
$ echo SHLVL
2
This is a useful variable, and I plan to make a “shellami” alias. Tight!