Tuesday, May 19, 2009

Setting a proxy server in Tomcat

Add the following lines to the catalina.properties file (N.B. These settings are for Unix systems. It may be different for Windows.)

http.proxyHost=[proxy ip address or dns]
http.proxyPort=
[proxy port]
http.nonProxyHosts=
[all hosts for which a proxy is not required (delimit each host with a '|']

Example:
http.proxyHost=10.113.49.49
http.proxyPort=8080
http.nonProxyHosts=localhost|10.*

Wednesday, May 6, 2009

scp: ambiguous target

I was attempting to secure copy a file over a remote server and I encountered the following error:
$ scp file.txt user@ip_address:"/file path/"
scp: ambiguous target

So after some trial and error I discovered the problem was the space " " in the path to which I was attempting to copy the file to (despite having put the path within quotes).

To solve this problem you need to escape the space e.g.
$ scp file.txt user@ip_address:"/file\ path/"

Tuesday, April 7, 2009

Running a command in unix that continues to run when you logout

It is often necessary to run a script/process in the background that continues to run when you logout. In Unix/Linux systems we make use of the nohup command e.g.
nohup java [java_class] &

The "&" indicates that the process should run in the background.

Tuesday, February 17, 2009

Counting the occurance of a string in a file

The following counts the number of lines the occurrence of the word "test" occurs in a file:
grep -c " test " filename

Counting all occurrences:
grep -o " test " filename | wc -w

Wednesday, January 28, 2009

Going through a file line by line in java

BufferedReader inFile = new BufferedReader("filename");
String line = null;
try {
   while ((line=inFile.readLine())!=null) {
      //do something with the line here
   }
}
catch (IOException ioe) {
   ioe.printStackTrace();
}