Saturday, February 25, 2006

unix tip: kill signal

this morning I had a problem starting up one program. from the error log its stated that the program exit with signal 6.
how do i know what is the signal 6 mean?
a friend of mine show me this :)
# kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL
5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE
9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2
13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD
18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN
22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO
30) SIGPWR 31) SIGSYS 33) SIGRTMIN 34) SIGRTMIN+1
35) SIGRTMIN+2 36) SIGRTMIN+3 37) SIGRTMIN+4 38) SIGRTMIN+5
39) SIGRTMIN+6 40) SIGRTMIN+7 41) SIGRTMIN+8 42) SIGRTMIN+9
43) SIGRTMIN+10 44) SIGRTMIN+11 45) SIGRTMIN+12 46) SIGRTMIN+13
47) SIGRTMIN+14 48) SIGRTMIN+15 49) SIGRTMAX-15 50) SIGRTMAX-14
51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10
55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6
59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX

and for more info about the signal, use
# man 7 signal

eventhough i know what its mean now but still i can't figure out what is the problem with the program :(

Friday, February 24, 2006

unix tip: sort processes by cpu/memory usage

you can use the following commands to sort processes by cpu/memory usage.

linux
cpu:
# top -bn1P

memory:
# top -bn1M
or just type top without any options, you'll get an interactive interface.

solaris
cpu:
# prstat -s cpu

memory:
# prstat -s size
Read more...

aix
cpu:
# ps -ef | egrep -v "STIME|$LOGNAME" | sort +3 -r | head -n 15

memory:
# svmon -P
summary of the top 15 processes using memory on the system, use the following command:
# svmon -Pt15 | perl -e 'while(<>){print if($.==2||$&&&!$s++);$.=0 if(/^-+$/)}'
or you can just use an topas.

Tuesday, February 14, 2006

unix tip: rename files - replace spaces with underscores

last week a friend of mine asked me how to rename a bunch of files that have spaces on its name.
this is what i came up with:
$ cat replace_spaces_with_underscores.sh
#!/bin/ksh
while read filenames
do
mv "$filenames" "`echo "$filenames"sed -e 's/ /_/g'`"
# use below line if you don't want to replace it with underscore
#mv "$filenames" "`echo "$filenames"sed -e 's/ //g'`"
done < filenames_with_spaces

but 1st u need to run this, dump filenames with spaces to one file:
$ ls grep " " > filenames_with_spaces

p/s: since i'm in nederland, maybe i should try their space cake :)

Sunday, February 12, 2006

den haag, nederland

my 3rd week in Den Haag, Nederland for 3 months business trip. the weather is freaking cold here that made me so lazy to go out. but on the 1st weekend i went to Amsterdam and got a chance to see the best part :)
hopefully i'll enjoy my stay here, like my buddy said for a few times, nice place!

Wednesday, February 08, 2006

unix tip: ssh - get rid of yes/no message

normally when you ssh to a new unix/linux box, you'll be prompted with yes/no message like below:

$ ssh hostname1
The authenticity of host 'hostname1 (ip_address_hostname1)' can't be established.
RSA key fingerprint is be:eb:c6:2f:0e:d9:56:38:8c:f7:17:cd:96:f9:3c:f5.
Are you sure you want to continue connecting (yes/no)?

most of the time you just type yes, key in your password and you are in the box. but how about you need to create a script to ssh to a few servers to run some commands? then this option become handy:

$ ssh -o StrictHostKeyChecking=no hostname1
username@hostname1's password:

key in your password and you are in and of course you can use ssh-agent to get rid of the password prompt as well :)