Friday, February 24, 2012

Install expect on Ubuntu 11

I missed auto log in to remote ssh server or doing automation that I often do. like access ftp server and download file, log in ssh server, push file to FTP server and open a turnelling so on.
There is a way to do very easily.

You need to install 'expect' command.
"expect" command is simply expecting a text from terminal, and send it when it meets expectation.
sudo apt-get install expect
Installation is done.

Sample usage.

Let's make simple shell program

Type into shell shell program.
#!/usr/bin/expect -f
set timeout 100
spawn ssh userid@servername 
expect "/home/devtrigger/.ssh/id_rsa" 
send "password\r"
expect "servername:"
send "bash\r"
you should not omit first line "#!/usr/bin/expect -f" it indicate that it will run by expect.
you can ommit "timeout 100" which is waiting for response from server. I used the timeout option for using long process like copy a big file from ftp or etc.
of course, you need to replace certain text like "devtrigger", "password"
save it.

let's make the file executable and run it
chmod 755

Host name change on Ubuntu 11

I had long long disliked host name on my terminal when I installed.
First thing, I wanted to do after installed Ubuntu.

Host name change on Ubuntu 11

Open up the text file that shows your Ubuntu local host name.
sudo gedit /etc/hostname

change to new name you want
Save it.

hosts file modify on Ubuntu

Hosts file modify on Ubuntu

sudo vi /etc/hosts

modify it and save it.

I have done it on Ubuntu 11.
I am quite sure most of Ubuntu version has same file location.

Oracle JDK 7 install on Ubuntu 11

For some reason, I guess because of license reason. Oracle doesn't have Ubuntu software repository.
so you need to install it manually, you can't use apt-get inatall command.
Let's see how to install Oracle(Sun) JDK 7 install on Ubuntu

Download jdk7 for linux, don't download rpm package.
rpm package is for Rad hat linux. just download tz , tar file extension

1.Extract files. up the terminal and type:

Move the extracted jdk folder to the default installation folder for java.
and make a link.
sudo mv jdk1.7.0 /usr/lib/jvm
ln jdk1.7.0_02 java-7-sun
sudo update-alternatives --config java

Next, type this command and count the number of java version you have.
sudo update-alternatives --config java

Once you have that number enter this command and change the number on the end of it to the number you just found plus one.

this command mean is, you add one more java command on system.
later on, you can switch to another java easily, like open jdk or another version of jdk.
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-7-sun/jre/bin/java 3

Finally, run this command and type the number of the new installation then hit enter.

sudo update-alternatives --config java

To make sure everything worked, run this command. It should output your version to be 1.7.0.

java -version

And that's it! Let me know if you have problems with anything.

you can have sevral jdk, if you made a link and used update-alternatives command.
you can switch jdk very easily
java-1.6.0-openjdk java-6-sun java-7-sun

java-6-openjdk java-6-sun- jdk1.7.0_02

open profile file
#sudo gedit /etc/profile 

type it in
export JAVA_HOME
export PATH=$PATH:/usr/lib/jvm/java-7-sun/bin

Thursday, February 16, 2012

Web server request and response via telnet

How to see web server response via telnet command.

As you know, most of network connection you can see via telnet.
Mail server, Web server, FTP server so on.

Now, I will show you how to access WEB Server via telnet.
There are many tool to see it better.
But, when you need only for simple reason to check, telnet is the good option to check.

telnet 80
GET / HTTP/1.0
'type enter 2 times'

When you are behind of proxy server. you should go through proxy. You need to telnet to your proxy server and connect.
Please see below example. is the proxy server ip and 8080 is the port number
telnet 8080
'type enter 2 times'
GET / HTTP/1.0
'type enter 2 times'

you can replace '/' character which is located after 'GET' to your demand like '/index.php', '' so on.
most of server use virtual host. so "Host" header is necessary to configure.
It should be basically same as host address with out any query string.

If you are interested more about header list
Please check this link

now, you can make your own script for regular check or application for performance test so on.

Wednesday, February 15, 2012

mybatis-spring 1.0.2 crash with springframework 3.1? introduce maven dependency exclusions

As a new in maven, after setting up maven dependency with springframework 3.1 and mybatis-spring 1.0.2 .
It crashed. It worked before I set up maven.
why it is not working with maven. Should I dump maven?

I was looking into it.
the reason was mybatis has dependency to spring 3.0.6. WTH
and bring spring 3.1 jars from my configurations and 3.0.6 jars from mybatis.


That's the solution to bring only spring 3.1 jars.

By they way, I had to type it all on by one. I was wonder if there is any smarter way with wild card.
like this. would it be working? it would be so great if it works.


But, It is not working, I hope it works soon.
Maven team is working on this.  there is already the same issue in maven jira

Maven eclipse plugin configuration "mvn eclipse:eclipse"

let me introduce maven eclipse plugin
there are all the eclipse plugin elements list below

Basically, I have configured most of needs for my self and our team.
When I make a maven project from eclipse and right mouse click.
I can see maven menu, there are add dependency, update dependency menu and so on.
but, when I made with the command mvn eclipse:eclipse the menu was not showed up.

I found that I need to add project nature on pom.xml


Completed one.
you can omit which you don't need.


I can see right .project file after run "mvn eclipse:eclipse" command



After :


now I can see "maven2Nature" is added.

Now on I will commit only source files and pom.xml to SVN.
then all of my team member will have same eclipse setting whether they use windows, linux or mac and all of them can see source files and java doc from eclipse. you can add same encoding setting and java jdk version so on.

Tuesday, February 14, 2012

Springframework 3.1 with quartz 2.1.2

I have looked into many samples, but most of spring batch sample was not working on springframework 3.1

It spit it out "java.lang.IncompatibleClassChangeError" error message.

There is an same issue, it mentioned that they have fixed this bug.

But, it was not working.
I have looked into their comments.

I need to use different bean class, just rename most of it with "Factory"

org.springframework.scheduling.quartz.JobDetailBean -> JobDetailFactoryBean like this

Samples batch are below that is running.

<bean id="urlConnectionJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean"
  <property name="jobDataAsMap">
    <entry key="informMatchingItemService" value-ref="informMatchingItemService" />
 <bean id="informMatchingItemService" class="service.InformMatchingItemServiceImpl"/>

 <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean"
  p:repeatInterval="20000" />
 <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
  <property name="triggers">
    <ref bean="simpleTrigger" />

In the End, It's working.
But, bad news is waiting. @Autowired annotation is not working. due to different class lifecycle between spring and quartz. I had to make setter and inject from xml configuration one by one.
There are already different solutions. but, not really meet my expectation and little messy to make clean code.

I decide to put spring batch and quartz out.
It's not necessary for making small batch program for my current project.

There is a good function, I decide to use Spring task and scheduler, that's very simple and easy.
Spring task example and I don't need spring batch jars and quartz jars. of course I can use @Autowired annotation.