Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

Monday, December 17, 2007

Tomcat java.net.BindException: Cannot assign requested address

I had a very strange error today when I tried to startup tomcat on some linux box that used to work. Since google was no help I figured I should document this somewhere.

Tomcat startup gave the notorious java.net.BindException: Cannot assign requested address. This usually means that another process is listening on the same port on this machine. I started with ps -ef grep java to make sure that no other tomcat process was running on the machine. Nothing.

I suspected that maybe some other web server was holding the port, but netstat -an showed that nothing binds this address. Moreover, telnet localhost 80 showed that no one is listening.

Looking at the server.xml I found out that the connector was binding to the hostname "demoserver" on port 80.

<Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
address="demoserver" port="80"
minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="100" debug="0" connectionTimeout="20000"
useURIValidationHack="false" disableUploadTimeout="true" />

trying to ping demoserver gave me errors, but nslookup demoserver gave me the right ip address.

After a few minutes I noticed that some clown added demoserver to /etc/hosts with the wrong ip address. Fixing /etc/hosts to have the right ip address for demoserver made tomcat work smooth and nice.

Tuesday, July 31, 2007

mysqltop.sh

If you need to monitor mysql proccesslist, dump the following to a shell script and chmod 755. (ofcourse you will need to add passwords etc. if you have any;)


#!/bin/sh

watch 'mysql<<EOF
show processlist;
EOF
'


(Control+C will let you out)

Sunday, June 10, 2007

Calcualting Average in UNIX Shell Script

I grabbed a piece of code to calculate an average for data in shell. It didn't work so I had to modify it. This is the result.


#!/bin/sh
n=0
sum=0
while read x
do
sum=`echo $sum + $x | bc`
if [ "$?" -eq "0" ]; then
n=`expr $n + 1`
fi
done
echo "scale=2;$sum/$n"| bc