Pages

Friday, February 17, 2012

IP Aliasing with ifconfig (Mac)

Hi

If you want to bind another IP address to your network card, you need to do IP aliasing. It will give you many IP address for a single nic.

It will help you if you need to start two server that listen on the same ports.

For example, I need to runs two differents systems that runs on 2 differents JBoss. I need to bind each JBoss to a specific IP to prevents port collision.

Here's how to add a new IP to your Mac or Linux.

Here's my IP informations

yannlaviolette@mac:~> ifconfig
lo0: flags=8049 mtu 16384
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
gif0: flags=8010 mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8963 mtu 1500
ether 00:1e:c2:0a:d6:2e
inet6 fe80::21e:c2ff:fe0a:d62e%en0 prefixlen 64 scopeid 0x4
inet 10.19.140.103 netmask 0xffffff00 broadcast 10.19.140.255
media: autoselect (100baseTX )
status: active
en1: flags=8863 mtu 1500
ether 00:1e:c2:a1:91:d1
inet6 fe80::21e:c2ff:fea1:91d1%en1 prefixlen 64 scopeid 0x5
inet 192.168.0.122 netmask 0xffffff00 broadcast 192.168.0.255
media: autoselect
status: active
fw0: flags=8863 mtu 4078
lladdr 00:1e:52:ff:fe:68:49:72
media: autoselect
status: inactive


To add a new IP, run this command: sudo ifconfig en0 alias 10.19.140.222 10.19.140.255 where 10.19.140.222 is the IP that I want to add and 10.19.140.255 is my broadcast address.


sudo ifconfig en0 alias 10.19.140.222 10.19.140.255

After the command I'm getting the following.

yannlaviolette@mac-jeanmat:~> ifconfig
lo0: flags=8049 mtu 16384
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
gif0: flags=8010 mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8963 mtu 1500
ether 00:1e:c2:0a:d6:2e
inet6 fe80::21e:c2ff:fe0a:d62e%en0 prefixlen 64 scopeid 0x4
inet 10.19.140.103 netmask 0xffffff00 broadcast 10.19.140.255
inet 10.19.140.222 netmask 0xff000000 broadcast 10.19.140.255
media: autoselect (100baseTX )
status: active
en1: flags=8863 mtu 1500
ether 00:1e:c2:a1:91:d1
inet6 fe80::21e:c2ff:fea1:91d1%en1 prefixlen 64 scopeid 0x5
inet 192.168.0.122 netmask 0xffffff00 broadcast 192.168.0.255
media: autoselect
status: active
fw0: flags=8863 mtu 4078
lladdr 00:1e:52:ff:fe:68:49:72
media: autoselect
status: inactive

To remove an IP, type the following command: sudo ifconfig en0 -alias 10.19.140.222 10.19.140.255

IMPORTANT!

If you need to ping your machine, you need to add a route to told your kernel that the new address is binded to 120.0.0.1. Type the following command

sudo route add -host 10.19.140.222 127.0.0.1



Friday, February 10, 2012

SOAP Web Services - Generating Java artifacts, JAX-WS

If you want to consume web services with Java and JBoss, you can use the JBoss tool "wsconsume" to build all the artifacts used to talk with the SOAP Web Service.

You need JBoss to achieve this.

The tool is in JBoss/bin. It is named wsconsume.sh

Here are the steps to generates the aritfacts
  1. Use the following command to generate the artifacts: wsconsume.sh -k -p com.mypackage http://127.0.0.1:8080/ws/jaxws/test?wsdl
  2. The tool will generate all the Java class required

Have fun!

Wednesday, December 21, 2011

Tuesday, December 20, 2011

Detaching a shell with "screen"

If you want to protect yourself against connectivity lost with Unix / Linux, screen is the perfect command for you.

In a shell, type the command screen.

It will create a new shell.

Launch the command that you want and close your shell window.

We your are back, type screen -ls to show the list of active screen session.

You will get something like this:

[06:19:36]$ screen -ls
There are screens on:
    11944.pts-0.myserver    (Detached)
    4859.pts-3.myserver    (Detached)
    12190.pts-4.myserver    (Attached)
3 Sockets in /var/run/screen/S-user.


Attached => The shell window is still active.
Detached => No open shell window.



To join the screen session, type screen -r 11944.pts-0.myserver where the parameter is the session name.



To logout, simple type exit


Complex find exec zgrep example

Suppose that we have a filesystem containing EDI transactions. Here's an example for the filesystem content:

/home/myhome/myfolder/mysubfolder/toto/good/toto.gz
/home/myhome/myfolder/mysubfolder/toto/fail/toto.gz
/home/myhome/myfolder/mysubfolder/tata/good/tata.xml
/home/myhome/myfolder/mysubfolder/tata/fail/tata.gz
/home/myhome/myfolder/mysubfolder/foo/good/foo123.gz
/home/myhome/myfolder/mysubfolder/bar/fail/ef3d.gz

We need to copy in the current directory all the EDI transactions (text file starting with ISA) from each folders (toto, tata, foo, bar) but the folder must start with a T. In our example we need to copy files from "toto" and "tata". The good transactions are in the folder "good". We must not copy transactions that are not contained in other folder than "good".

Also, the EDI files may be compressed. So we need to verify in compressed files... "toto.gz" contains an EDI file and "tata.xml" is a xml file.

The command is:
find /home/myhome/myfolder/mysubfolder/ -type f -iwholename *good* -iwholename *mysubfolder\/t* -exec zgrep -l '^ISA' {}  \; -exec cp -rf {} . \;

Will copy only "toto.gz"


find => Searching for something
-type f => Looking for files
-iwholename => The path should contains a specific word
-exec zgrep -l '^ISA' {} => Look for file including compressed one. File must start with ISA
-exec cp -rf {} .  => Copy the data to the current directory

Monday, December 19, 2011

Remove a specific directory from hierarchy

To remove a directory named DIRECTORY_NAME from a directory hierarchy

find . -type d -iname DIRECTORY_NAME -exec rm -rf {} \;

Moving EDI files

Moving all EDI files where the name contains -- to a folder named EDI.

find . -type f -iname *--*  -exec grep -Rl '^ISA' {} \; -exec cp -rf {} EDI/ \;