Sunday, April 27, 2008

check if a website is responding script

recently i needed to check if a website was responding, and if not, page myself (by sending an email to my pager). Here is the unix shell script i used to make this happen.

Required programs:
working mail (i use xmail on solaris 8 in this script)


## Script will check if the "host" is up, if the host is down, send an email
## You should cron it every 5 mins or so.

#uncomment to debug:
#set -x

## change these:

## locations of stuff:

now=`date '+%m/%d/%Y %H:%M:%S'`
rm ${log}
#when checking connection, do 2 tries, and time out in 7 seconds
${wget} -O /dev/null -t 2 -T 7 ${host} -o ${log}
grep "saved \[" ${log}
if [ $? = "1" ];
echo "site:[${host}] is down"
${mailx} -s "PRODUCTION is DOWN at ${now}" ${email} < ${log}
echo "site:[${host}] is up"

appfuse 1.8.1 ehcache NoSuchMethodError

I installed appfuse-light-all 1.8.1, installed acegi security, and ajax. After doing a build i get the following error when Spring starts up:

Error creating bean with name 'userManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]
.... bunch of other errors ...
Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: net.sf.ehcache.Cache.<init>

The problem here is that i am using an older version of ehcache for some reason. Doing a bit more digging shows that i have the following versions of ehcache in my M2 repository:

version 1.2.3 is what is messing things up for me, it gets loaded by Spring first and causes the error. Deleting that directory does not work because "ant deploy" does the following if the dependency is missing:

Buildfile: build.xml
[artifact:dependencies] Downloading: net/sf/ehcache/ehcache/1.2.3/ehcache-1.2.3.jar
[artifact:dependencies] Downloading: net/sf/ehcache/ehcache/1.2.3/ehcache-1.2.3.jar

Now, since i dont know how to use MAVEN, i cant remove the code that fetches the old version, so i do the evil hack to prevent it from being created:

remove the directory "1.2.3", make a copy of "1.3.0" directory, call it "1.2.3". rename all the files inside to say 1.3.0 instead of 1.2.3.

Also, if you are deploying to tomcat as a directory, you might need to go into the webapps directory in tomcat, locate your app, and its WEB-INF and delete ehcache-1.2.3.jar thats is probably there now.

Now you can use appfuse.

if anyone knows of a better way to solve this, leave a comment.

Friday, April 25, 2008

firefox: tab and enter do not work

I have been effected by the evil firefox bug which causes tab and enter to stop working. As of this writing there is no fix for this.

Here is what i have found out about living with this bug and other info:

1. shift-enter works instead of enter. No replacement for tab exists.
2. opening a new windows or restarting firefox fixes this problem for a while
- people suggested using session fix addon to remember your tabs while you restart firefox

other info:
1. people claim its a firebug issue or a web developer issue. i have both of those installed, by the way
2. there is a firefox bug report on this here
3. some posts on message boards which might eventually find a fix for this problem are:

at this point the best solution seems to use that session fix plugin, or maybe do a reinstall.

shell scripting with /bin/sh

I found this half decent tutorial / how-to on shell scripting with /bin/sh which i do lots but suck at.

here it is:

also, to check if a file DOES NOT exist:

if [ ! -e /path/to/file ];
# do something

ok i am done!

Tuesday, April 15, 2008

common regex cookbook

I see nice regexes on the java forums from time to time, i am going to add them all here for use!

Thursday, April 10, 2008

Escape cp-1252 chars in HTML

This is for when people paste crap from MS Word into html and add all those funky characters that looks horrible.

My friend gave me this perl one liner (ok, you can use it as a one liner if you wanted to) to escape the the evil CP-1252 characters in your HTML.

Notes for porting:
ord($1) converts capture group 1 to ASCII.
assumes $str has your html

the above regex replaces control chars!

Wednesday, April 09, 2008

Teamsite DCR java parser

Working with teamsite DCRs is painful. This is my attempt to make it a little bit less painful.

I made this program in order to make it easier to edit and parse teamsite data capture records. I should have done this a long time ago, and actually this is the first step towards freeing myself from OpenDeploy.

Anyway, here is the code for the parser:

Note: The code above does not yet truly support replicants, as in, you cant say 'give me the 3rd text field from the 2nd replicant..' unless you can figure out the xpath for it, which somewhat defeats the purpose of having a DCR parser.

Here is a driver class that uses my parser in order to do something silly.

in order to use this parser you will need the following libs: