vicker313 tech blog

January 28, 2010

Wireshark the Packet Sniffer in Linux

Filed under: Linux — Tags: , — vicker313 @ 7:56 am

Wireshark is a packet sniffer program that run on Linux machine (formerly known as Ethereal), and of course available to Windows as well. Basically it will record down what ever going through a specified port. To use it, you need to install the following packages:

  1. wireshark package: tools that do the sniffing.
  2. wireshark-gnome package: used to read the PCAP files created by wireshark (not sure whether can run in KDE or got KDE version or not).
  3. libsmi package: library required to install wireshark.

After everything is installed, you can execute wireshark using tshark command:


It will output a live packet sniffing to the terminal, however it is not much usage for this case. The following command is to run tshark in daemon mode and save the PCAP files in a specified location:

tshark -q -i eth0 -b files:80 -b filesize:10000 -w /root/trace/trace -x -t ad port 80

q: quiet mode or daemon mode

i: network interface

b: ring buffer option, which means it can set to save the data in multiple files in a mary go round pattern. files means how many files to save, filesize means maximum size of 1 single file (in KB)

w: file path where the PCAP file saved, aware that file number will be append to the file name when it is saved to multiple files.

x: tell wireshark to save the hex and ACSII dump

t: time format, ad means absolute date and time

port: which port to be sniffed

While to read the PCAP file, you need to be in Gnome Desktop and execute wireshark command:


A wireshark GUI program will appear, and all you need to do is open the PCAP file that you want to read.

This is the wireshark Startup Script (change the filename from wireshark.doc to wireshark), copy it to /etc/init.d and issue chkconfig --add wireshark to add it into services.


January 21, 2010

Install Tomcat Startup Script in Linux

Filed under: Tomcat — Tags: , — vicker313 @ 8:00 am

Make Tomcat auto startup in Windows is easy, either install it as service or just put the startup batch into Windows startup list. But not for Linux. After you install (or unzip) Tomcat into your Linux machine, and everything tested OK, you can use steps below to make Tomcat startup as service in Linux (referring to Startup script for Tomcat on Centos | Redhat | Fedora):

  1. Download the startup script from here. There are 2 files inside the zip file: tomcatd and tomcatRunner.
  2. Extract them to /etc/init.d. Make sure they are runnable.
  3. Edit parameters below inside tomcatd file:
    1. JAVA: location of your java utility, for example /usr/java/jdk1.6.0_17/bin/java.
    2. tomcatuser: user that will run the service, usually I just change it to root. (default is tomcat)
    3. CATALINA_HOME: location of your Tomcat, example /usr/tomcat.
  4. Make a tomcat directory in /var/run:
    mkdir /var/run/tomcat
  5. Add the tomcat service:
    chkconfig ––add tomcatd
  6. Now you should able to test out the service:
    service tomcatd restart

Here is another post to auto start Tomcat.

January 14, 2010

Change MySQL Database Location in Linux

Filed under: MySQL — Tags: , — vicker313 @ 8:00 am

Install MySQL in Linux doesn’t like in Windows, either install during OS installation or install separately, you can’t define the location you want the database to be located. Steps below is to change the location of the database (or reallocate):

  1. Stop MySQL service (the service name may be different)
    service mysql stop
  2. Copy MySQL data file to destination (usually the default database directory is /var/lib/mysql. Make sure the owner of the directory and files are mysql.
    cp -r /var/lib/mysql /destination
  3. Go inside the database directory and remove the log files (usually have 2).
    rm /destination/ib_log*
  4. Locate MySQL configuration file. You can find it at /etc/my.cnf. If no such file exists, copy a sample of configuration file from /usr/share/mysql/. There will be a few files to be selected (named as my-xxx.cnf). Copy any of them to /etc and rename to my.cnf.
  5. Edit MySQL configuration file. Go to section mysqld and look for the keyword datadir (add in if not exist). Change the location to the destination.
  6. Start MySQL service and done.
    service mysql start

January 7, 2010

Migrate Data using Transportable Tablespace in Oracle

Filed under: Oracle — Tags: , — vicker313 @ 8:00 am

There are few types of data migration methods: offline migration, migrate using exp and imp utilities, migrate using expdp and impdp utilities and of course using transportable tablespace. You can refer Oracle Database Cross Platform Transportable Tablespace for more details.

To perform migration using transportable tablespace:

  1. At source database, make the tablespace readonly
    alter tablespace users read only;
  2. Export it as SYSDBA
    exp file=exp.dmp log=exp.log tablespaces=users transport_tablespace=y
  3. Copy over the dump file and the tablespace data files to the destination
  4. At source database, put the tablespace back to read write mode
    alter tablespace users read write;
  5. If the same tablespace exists in the destination database, make  it offline and drop it.
    drop tablespace users including contents and datafiles;
  6. Lastly import the copied dump file:
    imp file=exp.dmp log=exp.log tablespaces=users transport_tablespace=y datafiles=('/u01/users01.dbf', '/u01/users02.dbf')

If there is error such as “Package DBMS_PLUGTS not exist”, try:

  1. Execute this SQL file to create the package in SYS user: {ORACLE_HOME}/rdbms/admin/dbmsplts.sql
  2. Log into the user you want to import the data, create a synonym to the package
    create synonym dbms_plugts for sys.dbms_plugts;
  3. Re-run the import command

Blog at