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());
}

Thursday, February 17, 2011

Wednesday, February 9, 2011

About chmod...

1. set it readable only for outsiders:
Before: -rwxr-xr-x  archive.sh
Command: chmod o=r archive.sh
After: -rwxr-xr--  archive.sh
2. Take away all permissions for the group for topsecret.inf
Before: -rw-r-----  topsecret.inf
Command: chmod g= topsecret.inf
After: -rw-------  topsecret.inf
3. Open up publicity.html for reading and writing by anyone.
Before: -rw-r--r--  publicity.html
Command: chmod og=rw publicity.html
After: -rw-rw-rw-  publicity.html

Passwordless SSH connection

Spend the whole day to figure out how it works = ="

This is the scenario where server A wants to establish a connection to B without keying password:

a) Log in Server A with user Id 'userA' and corresponding passowrd.

b) Create the keys in server 'A' with the following command.
/user/local/bin/ssh-keygen –t rsa

c) Copy the public key in id_rsa.pub file under HOME_DIRECTOR/.ssh directory of server 'A'

d) Copy the 'id_rsa.pub' file of server A to 'authorized_keys' file of server B in B's HOME_DIRECTORY/.ssh directory

e) Grant both .ssh/ of server A & B 700 (chmod -R 700 .ssh/)

f) Log into server 'A' with 'userA' user ID

g) Execute the sftp command for server B, eg. sftp userB@Bserver



Tuesday, February 8, 2011

Current time

$ date
Tue Dec 19 21:16:03 CST 2000 
$ date +"%m" 
12 
$ date +"%B"
December
$ date +"%Y-%m-%d" 
2000-12-19
$

Monday, February 7, 2011

Simple awk Command to de-deplicate file

$ cat file.txt
DD:12:A
AA:11:N
EE:13:B
AA:11:F
BB:09:K
DD:13:X

#Based on first field. Duplicates are DD,AA
$ awk '!x[$1]++' FS=":" file.txt
DD:12:A
AA:11:N
EE:13:B
BB:09:K

Again,

$ cat file.txt
DD:12:A
AA:11:N
EE:13:B
AA:11:F
BB:09:K
DD:13:X


#This time, based on first and 2nd field.Only duplicate combination is (AA:11)
$ awk '!x[$1,$2]++' FS=":" file.txt
DD:12:A
AA:11:N
EE:13:B
BB:09:K
DD:13:X