Tech Notes
show all process information with ps
$ps axww
The a option displays all process information other than your own.
The x option displays process information for those with no terminal; in other words, daemons and such.
The ww option tells ps to display all process information regardless of the window size. Info will be wrapped to the next line and not cut off like normal.
Ps is useful for getting information about what and how processes are running on your system. But normally, ps truncates each line at the width of the terminal window. The ww option prevents the truncation; very useful for when you know a certain string exists in the process line and you want to pass it to grep.
Old Greenwich Traffic Calming
My neighbors have banded together to implement a traffic calming program on our streets. Read the about the goals and progress of our efforts on the Old Greenwich Traffic Calming site.
How to find listening tcp processes
Sometimes you need to know what services are listening to what ports on your unix box. Two utilities that can get you some of this port and process information are netstat and lsof.
With netstat, you can find out which services are listening under which ports:
# netstat -na
The n option prevents ip to hostname lookups.
The a option adds to the output the sockets used by server processes.
Part of the output of the above netstat command will look like this (foreign ips have been x'd out to protect the innocent) :
$ netstat -na
Active Internet connections (including servers)
bash floating point arithmetic
Bash supports arthmetic but it does not support floating point arithmetic.
For example
bash$ echo $((1 + 1))
2
bash $ echo $((1 + 1.1))
-bash: 1 + 1.1: syntax error in expression (error token is ".1")
Bash will treat the floating point number as a string.
However, the utility bc does handle floating point arithmetic and can
be called from within bash scripts.
Here we call it from the command line:
bash$ echo "1+1" | bc
2
bash$ echo "1+1.1" | bc
2.1
Delete a file whose name begins with a dash
When using a unix terminal, sometimes you make typos and end up creating files starting with a dash "-"
For example, instead of typing
$touch ./h-ello.txt
if you ended up typing
$touch ./-hello.txt
this would create a file named -hello.txt
Trying to delete a file with a name starting with a dash will cause an error in the bash shell:
$rm -hello.txt
rm: invalid option -- h
Try `rm --help' for more information.
To get around the dash in the filename, use a double-dash "--" before the rm arguments to delete the file starting with a dash.
Using tail and awk to view part of a logfile
Logfiles can often contain information that is not immediately helpful while diagnosing a problem. For example, we may be only interested in finding what files are being currently requested via the apache log files. A typical log line would look like this:
1.2.3.4 - - [16/May/2007:07:49:50 -0700] "GET /index.php?main_page=product_info&manufacturers_id=6481&products_id=107321 HTTP/1.1" 200 5614 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" "-"
Counting the elements in this line separated by spaces, we identify that the elements of the log line are:
fixing stale jdbc dbcp connections with testOnBorrow and validationQuery
I've recently had problems with a webapp running in tomcat trying to use a stale jdbc connection via the apache commons database connection pools library (dbcp). I fixed this problem by adding a validation query to the configuration in the webapp's context.xml file. The documentation
for dbcp options is here:
http://jakarta.apache.org/commons/dbcp/configuration.html
The change involves adding the testOnBorrow parameter explicitely to the
configuration (although by default this is set to true). However, for the testOnBorrow setting to work, you have to specify a select sql query for dbcp to validate against the database before the connection is handed to the user code. In my case, I reused the basic select from the dbcp examples 'select 1' - use the validationQuery parameter to specify the sql query.
a href usage
The link html tag
Basic usage
<a href="http://www.crumpeta.com">tech hints</a>
Link titles
The text in the link title will appear when the mouse is placed on top of the link. link title example link
<a href="http://www.crumpeta.com" title="Tech hints and notes">tech hints</a>
Page loading options
open up page in the entire window
Use this link option to bust out of frames.
full browser window example link
Including data in a perl script
Sometimes you want to include data in a perl script and not want to include the data within the code itself. With perl, you can do this by using the __END__ label and reading the data in via the DATA filehandle. For example:
#!/usr/bin/perl
while ($line = <DATA>)
{
chomp $line;
push (@whoishere, $line);
}
for ($i = 0; $i <= $#whoishere; $i++)
{
print "$whoishere[$i] is at line #$i\n";
}
__END__
you
me
us
them
will print out:
you is at line #0
me is at line #1
us is at line #2
them is at line #3
Creating DSA key for remote SSH login
This is a simple and bare bones way to create a dsa key to connect from one server to another via ssh without using passwords. In plain english: How to connect from your unix (most likely mac os x) computer to your server without typing in a password.
Say you want to connect from your computer, mason, to a remote server, dixon, running ssh.
In your home directory in mason, you need to create a DSA key:
$ssh-keygen -t dsa
Enter file in which to save the key (/home/alan/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again: