31 January 2011

LINUX - netstat


1. Using Netstat to Count TCP Connection States

netstat -an|awk '/tcp/ {print $6}'|sort|uniq -c

2. List TCP/UDP and it's PID
netstat -tuvnap

APACHE - Redirect http requests to https

First make sure Apache is configured for HTTPS connection and necessary SSL certificates are installed.

No non-ssl access i.e. only accept https connections

Now open httpd.conf or .htaccess file (mod_rewrite not required):
# vi httpd.conf

Append following line :
Redirect permanent / https://mail.nixcraft.com/

Any request made to http://mail.nixcraft.com will goto https://mail.nixcraft.com/

Save and close the file. Restart the Apache:
# systemctl restart httpd

LINUX - How to Tell 32 or 64-bit?

# getconf LONG_BIT

25 January 2011

LINUX - Determine number of CPU cores


# cat /proc/cpuinfo | egrep “physical\ id|core\ id”





physical id : 0
core id : 1
cpu cores : 2

If you have two CPUs in cpuinfo with the same physical id and core id, than – hyperthreading! When you have all CPUs with different physical ids, than you have SMP, and when you have CPUs with one physical id and different core ids – you have one multicore CPU. And so on…

22 January 2011

PostgreSQL - Migrating from Oracle to Postgres Using ora2pg

# tar xzf ora2pg-7.x.tar.gz
# cd ora2pg-7.x/
# perl Makefile.PL
# make && make install

# perl -MCPAN -e 'install DBI'

# export ORACLE_HOME
# export LD_LIBRARY_PATH=$ORACLE_HOME/lib
# perl -MCPAN -e 'install DBD::Oracle'

Edit /etc/ora2pg/ora2pg.conf to modify ORACLE_HOST ORACLE_USER ORACLE_PASSWORD

LINUX - Loading data into database table

Example: To load username from /etc/passwd into a database table.

awk -F: '{print $1}' /etc/passwd > passwd_txt

cat passwd_txt | while read username; do echo "insert into {TABLE} (USERNAME,GROUPNAME,PRIORITY) values (""'$username'"", 'acct', 0);" >> users.sql; done;

LINUX - awk


To print single column from a text file
#awk -F: '{print $1}' /etc/passwd

To print multiple columns from a text file
# awk -F: '{print $1,$7}' /etc/passwd

Wordpress - Local installation in Vmware

If you're interested in exploring website design with WordPress, this guide will help you set up a WordPress instance on your local mach...