Blog O' Matty


Helpful shell shortcuts

This article was posted by Matty on 2008-12-22 10:54:00 -0400 -0400

So this may be a little basic, but I find myself using these two shortcuts quite a bit while at the shell.

If you ever find yourself wanting to “reuse” the last argument in a command – for example, here I move a file from one location into /var/tmp and I want to “cd” into /var/tmp without having to type it, use the shell variable !$…

locutus:~ (svoboda)> dd if=/dev/zero of=/tmp/blah bs=1024000 count=1 1+0 records in 1+0 records out 1024000 bytes (1.0 MB) copied, 0.0109023 s, 93.9 MB/s

locutus:~ (svoboda)> mv /tmp/blah /var/tmp

locutus:~ (svoboda)> cd !$ cd /var/tmp

locutus:/var/tmp (svoboda)> pwd /var/tmp

If you wanted to “preface” your last command, you can throw anything you want into the shell followed by the !! shell shortcut. locutus:/var/tmp (svoboda)> “Armin van Buuren’s a State of Trance” -bash: Armin van Buuren’s a State of Trance: command not found

locutus:/var/tmp (svoboda)> echo !! echo “Armin van Buuren’s a State of Trance” Armin van Buuren’s a State of Trance

The first line mearly “shows” what is being executed, with the second line executing the actual command.  Not rocket science, but whatever helps on saving keystrokes!

OpenSolaris IPS repository offerings growing

This article was posted by on 2008-12-04 10:55:00 -0400 -0400

I’m really glad to see the OpenSolaris IPS repositories growing with the amount of available packages.  Large network repositories of thousands of software packages make Fedora and Ubuntu the great, easy to use Linux distributions that they are.  Extending the amount of packages available to OpenSolaris just builds upon this usability!

A graph explaining the IPS repository structure, the forum post showing how to enable the pending repository, and a complete list of the 1708 pending IPS repository packages can be found here.

The OpenSolaris community really needs people to assist in finding / submitting any found bugs within these packages.  If you were looking for a way to assist the OpenSolaris community, here’s your chance!

Snooping loopback interfaces on Solaris hosts

This article was posted by Matty on 2008-12-03 19:38:00 -0400 -0400

One thing that I have always enjoyed about Linux is the ability to snoop traffic on loopback interfaces. This is extremely useful for debugging local communication problems, and the fact that you couldn’t until recently do this on Solaris hosts was extremely annoying(especially in the world of zones!). I just read Peter Memishian’s blog entry on the IP observability code that was recently putback into opensolaris, and low and behold you can now snoop loopback interfaces on Solaris hosts. This is awesome, and the ability to snoop by zone id is by far my favorite feature:

$ snoop -I bge0 zone 1

The Solaris network stack just keeps getting better and better, and with the upcoming crossbow and IPMPng putbacks just around the corner, networking in Solaris will only get better. Now if only we could get Sun to address some of the performance bugs in the networking stack!

Viewing Solaris zone resource utilization

This article was posted by Matty on 2008-11-25 21:23:00 -0400 -0400

Solaris zones have been around for quite some time now, and provide low overhead execution environments for running application. Admins who need to understand how zones are utilizing CPU and memory resources typically turn to prstat, which provides the “-Z” option to view utilization by zone:

PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
448 foo 165M 141M sleep 59 0 21:47:34 37% java/115
7713 matty 2292K 1740K cpu0 59 0 0:00:00 0.0% prstat/1
233 snmp 7348K 5336K sleep 59 0 0:00:46 0.0% snmpd/1
316 daemon 2100K 1344K sleep 60 -20 0:00:00 0.0% lockd/2
309 root 1752K 944K sleep 59 0 0:00:00 0.0% sac/1
492 root 8688K 7740K sleep 29 0 0:00:01 0.0% svc.startd/11
459 root 0K 0K sleep 60 - 0:00:00 0.0% zsched/1
129 root 2192K 1328K sleep 29 0 0:00:00 0.0% syseventd/14
123 root 2964K 2024K sleep 29 0 0:00:00 0.0% picld/5
202 root 2432K 976K sleep 59 0 0:00:00 0.0% cron/1
402 root 3520K 1328K sleep 59 0 0:00:00 0.0% sshd/1
136 root 6552K 3772K sleep 29 0 0:00:00 0.0% devfsadm/9
303 daemon 2432K 972K sleep 59 0 0:00:00 0.0% rpcbind/1
140 root 4376K 3120K sleep 59 0 0:00:02 0.0% nscd/24
137 daemon 3892K 2036K sleep 29 0 0:00:00 0.0% kcfd/3
236 nobody 3324K 1044K sleep 59 0 0:00:03 0.0% nrpe/1
827 root 9176K 8144K sleep 59 0 0:00:03 0.0% svc.configd/14
823 root 2160K 1248K sleep 59 0 0:00:00 0.0% init/1
421 smmsp 7072K 1492K sleep 59 0 0:00:00 0.0% sendmail/1
9 root 9516K 8504K sleep 29 0 0:00:03 0.0% svc.configd/15
ZONEID NPROC SWAP RSS MEMORY TIME CPU ZONE
0 35 213M 215M 1.3% 21:49:10 37% global
3 21 43M 50M 0.3% 0:00:15 0.0% zone1
1 21 43M 50M 0.3% 0:00:15 0.0% zone2
2 21 42M 50M 0.3% 0:00:16 0.0% zone3

While reviewing the Solaris zones mailing list last night, I noticed that Jeff Victor posted a link to a Perl script that can provide utilization data for zones. This script has a TON of potential, especially once it is able to report on network and disk utilization.

Deciphering shell exit codes

This article was posted by Matty on 2008-11-20 00:19:00 -0400 -0400

I was recently debugging an issue with a shell script, and noticed that the shell was exiting with an exit code greater than 100 when it received a SIGTSTP signal:

$ cat test

#!/bin/bash
sleep 60

$ ./test

[1]+ Stopped ./test
Home:~ matty$ echo $?
146

$ kill -18 4667

I was curious where the exit value of 146 came from, so I did a bit of digging. It turns out that when a shell exits due to an uncaught signal, the signal number is added to 128 and that is the value that is returned. So in the case above, the exit code 146 was returned. I digs me some random shell knowledge.