Sunday, August 21, 2011

How to modify IP, default gateway in Linux

Use Ifconfig, specifiy the network card to be modify and the values, it should be effective after the command:
  
# ifconfig eth0 192.168.0.20 netmask 255.255.255.0

One can also modify it at the file which specifies the network setting, this method requires a restart of the :

#vi /etc/sysconfig/network-scripts/ifcfg-eth0
          
            DEVICE=eth0
            BOOTPROTO=static
            BROADCAST=192.168.202.255
            HWADDR=00:09:6B:09:0E:BE
            IPADDR=192.168.202.244
            NETMASK=255.255.255.0
            NETWORK=192.168.202.0
            ONBOOT=yes

 Change the default gateway that take in effect immediately:
 # route add default gw 192.168.0.254

or

#vi /etc/sysconfig/network

           NETWORKING=yes
           NETWORKING_IPV6=no
           HOSTNAME=x3451
          GATEWAY=192.168.202.254

Ti restart the network card, the command is:

#/etc/init.d/network restart

Sunday, August 14, 2011

How to move 2Gb or bigger file in a script

#!/bin/sh

find /backup/include -printf '%s %p\n' | while read size name; do
    if [ "$size" -gt 2000000000 ]; then
        mv -i "$name" /backup/exclude
    fi
done
  

Tuesday, July 26, 2011

How to load user preference at user login

At Linux/Unix, user can set preference value(e.g. alias, folder and file default color). These values are loaded from a startup file every time when a user logs in or by excecuting the "source {filename}" command.

Startup file are different from one shell to and other. To confirm what the current shell is, simply do the command "echo $shell", and it will be shown on the screen. The startup file usually stored at the default root directory - usually this is the first location where a user hits after the login.

There are always some overly cautious administrator would assign the user to another directory other than the default root directory by executing a cd command at the startup file for the sake of safety. In this case, one must first guess what the the default root directory is by the username and have a search in the /usr/ directory.

Startup file are usually invisible(filenames with "." at the front) to the user, to make it visible, do "ls -a" and edit it with your default editor.

Startup file name by Shells:
.login      --      csh shell
.tcshrc    --     tcsh shell

A sample Startup script:

#set environment

#alias
alias lla 'ls -lrta'
alias ll 'ls -lrt'
alias ls 'ls -x --color'
alias pwd 'echo $cwd' # This is faster than executing the pwd command
alias rm '/bin/rm -i'
alias checkdate 'ls \\!^ | awk -F. {print $1 $7} | sort -u'

setenv LS_COLORS 'no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:'

Monday, June 27, 2011

SQLPLUS Command using cronjob

Spend three days to figure out how to copy an oracle DB table from a cronjob.

After some intensive surfing for reference online, finally realize what I miss is the declaration.
It is worthy to note down:

For sh:

#!/bin/sh

ORACLE_HOME=/DB/HOME
export ORACLE_HOME
ORACLE_BASE=/DB/HOME
export ORACLE_BASE
ORACLE_OWNER=oracle
export ORACLE_OWNER
ORACLE_SID=MYDBID
export ORACLE_SID
NLS_LANG="american_america.we8iso8859p1"
export NLS_LANG

HOME=/HOME/DIR/

PATH=/usr/bin:/bin:/usr/local/bin:$ORACLE_HOME/bin
export PATH

sqlplus -s username/password@MYDBID @${HOME}/script.sql >> ${HOME}/something.txt

For csh:

#!/bin/csh

setenv ORACLE_HOME /DB/HOME
setenv ORACLE_BASE /DB/HOME
setenv ORACLE_OWNER oracle
setenv ORACLE_SID MYDBID
setenv NLS_LANG "american_america.we8iso8859p1"

set HOME = /HOME/DIR/

setenv PATH /usr/bin:/bin:/usr/local/bin:$ORACLE_HOME/bin

sqlplus -s username/password@MYDBID @${HOME}/script.sql >> ${HOME}/something.txt

-hayashi

Friday, April 8, 2011

Tuesday, February 22, 2011

Tokenizer

Java: 
 
String speech = "Four score and seven years ago";
StringTokenizer st = new StringTokenizer(speech);
while (st.hasMoreTokens()) {
  println(st.nextToken());
}