Thursday, December 2, 2010

yum plugin to remove dependencies

You can remove dependencies using yum-plugin-remove-with-leaves plug-in.

To install:

# yum install yum-plugin-remove-with-leaves

To use:
# yum remove --remove-leaves <package-name>

That's all folks :)

Friday, November 26, 2010

Using markers in vi/vim

This feature is useful if for example we want to delete a few lines or characters but we are too lazy to count the lines or characters to use dd or dw command. We can set up to 26 marker using lowercase a-z as the marker's name. The main usage of marker is to mark any location in file.

How to use (we put 'a' as the marker's name):

ma - mark current cursor position as marker named 'a'
`a (backquote a) - move to character marked as 'a'
'a (quote a) - move to first non blank character (line) containing marker 'a'
`` (backquote backquote) - move to last operated marker or toggles with last cursor position, if no marker is set, cursor moves to beginning of file (BOF)
'' (quote quote) - move to beginning og line (BOL) operated marker or toggles with BOL of last cursor position, if no marker is set, cursor moves to BOF

Example on using marker:

If you want to indent 5 lines starting from current line: majjjjj>'a
If you want to delete five words using marker: mawwwwwmb`ad`b

That's all friends :)

Saturday, November 13, 2010

Edit main menu in fedora

Starting from fedora 12, I found out that I cannot edit my main menu anymore. This is kind of frustrating since I installed many custom applications, and I would like it to be easily accessible from the main menu. After searching around, i found out that one package is not included in fedora 12 livecd. The package is called alacarte.

$ rpm -qi alacarte
Name : alacarte Relocations: (not relocatable)
Version : 0.12.4 Vendor: Fedora Project
Release : 1.fc12 Build Date: Tue 22 Sep 2009 08:41:26 AM MYT
Install Date: Sat 13 Nov 2010 07:17:32 AM MYT Build Host:
Group : Applications/System Source RPM: alacarte-0.12.4-1.fc12.src.rpm
Size : 367423 License: LGPLv2+
Signature : RSA/8, Thu 01 Oct 2009 03:42:28 AM MYT, Key ID 9d1cc34857bbccba
Packager : Fedora Project
Summary : Menu editor for the GNOME desktop
Description :
Alacarte is a graphical menu editor that lets you edit, add, and delete
menu entries. It follows the menu specification and
should work with any desktop environment that uses this specification.

So, just install the alacarte package using yum, and select "System -> Preferences -> Main Menu", and you can now edit your main menu.
# yum install alacarte -y
That's all folks

Tuesday, October 26, 2010

Xen's domU always depend on dom0's time and date

By default, the time and date in domU is following dom0. To reset that, below are just what you have to do to decouple the domU's date from dom0

On dom0:

Append xen.independent_wallclock=1 to /etc/sysctl.conf

# echo "xen.independent_wallclock=1"  >> /etc/sysctl.conf
Activate the change
# sysctl -p
Append extra="clocksource=jiffies" to the domU's configuration file.
# echo "extra=\"clocksource=jiffies\"" >> /etc/xen/<domU's name>.cfg 

On domU:

Append xen.independent_wallclock=1
# echo "xen.independent_wallclock=1"  >> /etc/sysctl.conf 
Activate the change
# sysctl -p 
Append jiffies to /sys/devices/system/clocksource/clocksource0/current_clocksource
# echo "jiffies" >> /sys/devices/system/clocksource/clocksource0/current_clocksource

Now you can set your domU's date using "date" command or "ntpdate" to get update from ntp servers.

That's all folks

Friday, October 15, 2010

Using ssh as proxy

To create ssh tunnel is very easy. Let's say you want to use as your ssh proxy, your username is foo and you choose port 8080 on your localhost to be your local proxy port. Type below command on your localhost:

$ ssh -D 8080
Once connected, set your browser to use Socks5 proxy on port 8080 on your local machine. For firefox, the setting is "Tools -> Options -> Advanced -> Network -> Settings -> Manual proxy configuration" and follow below picture for the proxy setting. Just make sure to keep the ssh connection connected to reap the ssh proxy benefits :)

That's all :)

Cygwin man search problem

If you are a windows user, and you use cygwin, there is a problem with man page. The search function is a bit weird, where it cannot find something like "-D" in ssh man page. To overcome this, you have to set the LANG environment variable to c. To do this, just add export LANG=c to your .bashrc:

$ echo "export LANG=c" >> .bashrc

That's all folks :)

Thursday, October 7, 2010

Forcing user to change password the first time they log in

If you are creating new user in your machine, and you would like them to change password the first time they login, using command chage is the way. Let's say our user is foo.

# chage -d 0 foo
where -d is for lastday. When we set it to 0, it will ask for password change the first time foo logs in.

That's all folks :)

Wednesday, August 11, 2010

Installing apache mod_fastcgi(fastcgi module) on CentOS 5

In the previous post, I have written about installing apache mod_fcgid module to enable fastcgi support on apache. This time, I will write on how to install mod_fastcgi module to enable fastcgi module on apache installed on CentOS 5. Since by the time of this writing, there is no rpm for apache mod_fastcgi, we have to compile the mod_fastcgi module.

1. Install requirements for compilation

# yum install httpd-devel apr apr-devel libtool

2. Download latest mod_fastcgi source code
# cd /opt
# wget

3. Untar the package.
# tar -xvzf mod_fastcgi-current.tar.gz

4. Install the module. You can find the installation guide on the INSTALL.AP2 file. We have to specify top_dir in the make and make install commands because we install apache2/httpd using yum
# cd mod_fastcgi-2.4.6
# cp Makefile.AP2 Makefile
# make top_dir=/usr/lib/httpd
# make install top_dir=/usr/lib/httpd

5. Add "LoadModule fastcgi_module modules/" to /etc/httpd/conf/httpd.conf to tell apache to load the new module

6. Restart apache
# /etc/init.d/httpd restart

7. You can assure that the mod is loaded by apache2, by looking at /var/log/httpd/error_log
# grep -i "FastCGI" /var/log/httpd/error_log 

[Wed Aug 11 12:26:27 2010] [notice] FastCGI: process manager initialized (pid 8853)

That's all :)

Installing apache mod_fcgid(fastcgi module) on CentOS 5

For apache to support FastCGI, you have to install either mod_fastcgi or mod_fcgid. In this example, I will show how to install mod_fcgid on existing apache webserver on centos 5.

First of all, the rpm is available at kbsingh's centos testing repository.To install kbsingh's centos repository:

1. Download kbsingh-CentOS-Extras.repo to /etc/yum.repos.d/

# cd /etc/yum.repos.d
# wget

2. Enable karansingh's testing repo by setting gpgcheck to 0 and enabled to 1 in the [kbs-CentOS-Testing]
# sed -i "s/enabled=0/enabled=1/g" /etc/yum.repos.d/kbsingh-CentOS-Extras.repo

3. Install mod_fcgid
# yum install mod_fcgid

4. Restart apache, and verify whether fcgid_module is available by using the second command below
# /etc/init.d/httpd restart
# httpd -t -D DUMP_MODULES

5. If the module is still not loaded, add "LoadModule fcgid_module modules/" to your /etc/httpd/conf/httpd.conf, and restart apache.

That's all :)

Monday, July 5, 2010

Resetting windows password using linux livecd

The application that we are going to use is chntpw. In this example, we will be using ubuntu livecd.

1. Put the livecd in the cd/dvd drive and boot your windows machine from the livecd.

2. Once booted, open the terminal and check for tool named "chntpw". If not there, you can install it using:

$ sudo apt-get install chntpw

3. After the tool is ready, mount the windows partition. Use "fdisk -lu" to check which partition should be mounted. To mount /dev/sda1 (assuming your windows partition is on /dev/sda1), use below command:
$ sudo mount /dev/sda1 /mnt

4. Find SAM file on the windows partition. Usually it is located in Windows/System32/config. Run the chntpw on the SAM file.
$ cd /mnt/Windows/System32/config
List all user in the SAM record
$ chntpw -l SAM
Interactively edit user credential
$ chntpw -i SAM

5. Follow the wizard of chntpw and clear administrator or any user's password that you want to access.

6. Save changes and restart machine. You can access the windows without password for administrator and users that you have cleared their password. Make sure you take out the livecd, otherwise the machine will boot into it instead of windows.

Friday, June 11, 2010

Checking hardisk information on linux

To check hardisk information such as model and serial number, there are a few useful commands like hdparm, sdparm and fdisk.

To check the information about first hardisk for PATA and SATA hardisk:

# hdparm -i /dev/sda

For SCSI disk, a different command is to be used:
# sdparm /dev/sda

To check the hardisk capacity and partitions contained in the hardisk, fdisk can be used:
# fdisk -lu /dev/sda

If your hardisk is smart compatible, you can refer here on how to install and use smart to find information and monitor the health of your hardisk.

Tuesday, June 8, 2010

Getting netbios name in linux

If you are using linux and administering a network full of windows machine, there is a tool called nbtscan to easily scan through the network and list all machines with their netbios name.

To install nbtscan in fedora:

# yum install nbtscan

To use it on single machine(let's say the machine's ip is
# nbtscan

To scan the whole class C and list netbios names:
# nbtscan

To scan ip range:
# nbtscan

To get all options to use nbtscan:
# nbtscan -h

Tuesday, May 11, 2010

Backup and restore mysql databases

To backup(dump) single mysql database to a file:

mysqldump -u foo -p foodb > foodb.sql

where -u is for username, -p is for mysqldump to ask for password, foodb is the name of the database and foodb.sql is the file to dump the database.

To backup(dump) all databases to a file:

mysqldump -u foo -p --all-databases > alldb.sql

where -u is for username, -p is for mysqldump to ask for password, --all-databases is to tell mysqldump to dump all databases available and alldb.sql is the dumpfile name.

To restore back mysql database from dumpfile:

1. From terminal

mysql -u foo -p foodb < foodb.sql

-u and -p are similar to above, foodb is the name of the database and foodb.sql is the name of the dumpfile.

2. From inside mysql console where you have to access mysql console first:

mysql> source foodb.sql
mysql> \. foodb.sql

where foodb.sql is the dumpfile

Wednesday, April 21, 2010

Allowing full access to apache subdirectory

Usually, people will set basic authentication for apache directory (normally /var/www/html in centos). The reason is to protect the directory from unauthorized access. But what if a subdirectory inside (let say /var/www/html/mydirectory) needs full access? This is where .htaccess file comes into picture. To allow access to /var/www/html/mydirectory while maintaining authentication for /var/www/html, just follow below steps:

1. Go to /var/www/html/mydirectory
# cd /var/www/html/mydirectory

2. Create .htaccess file
# touch .htaccess

3. Put below items into that .htaccess file
Allow from all
Satisfy Any

4. You can try access http://servername/mydirectory using your browser. If still cannot access without password, try restart your apache
# httpd -k graceful

That's all :)

Friday, April 2, 2010

Creating maintenance page for apache

Sometimes we have to put our sites into maintenance mode for any reason, below is the easy way to do it for apache server in centos server.

1. Create a directory named err/ in the root directory. Lets say the site is called
# cd /var/www/html/
# mkdir err

2. Create a file named 503.html in the err directory
# cd /var/www/html/
# touch 503.html

3. Put maintenance message into 503.html (this is an example, you can put whatever message you want, and you can put any name for the file :))
# echo "<html><b>This site is currently under maintenance. Thank you</b></html>" > 503.html

4. Add below lines to your virtual host setting for

ErrorDocument 503 /err/503.html
## uncomment below to enter maintenance mode
RedirectMatch 503 ^/(?!err/)

5. Restart apache server
# httpd -k graceful

6. Test the website :)

Friday, March 26, 2010

Grepping ip address accurately

Let's say we have one log file named logfile.log that contains a few lines like below:

When we want to search for, we usually will use:

$ grep logfile.log

But unfortunately the result is not as what we expected(I assume we expect only will come out) because grep will show to us all results "containing" the pattern given by us.

To overcome this problem, we have to use grep like this:

$ grep "\>" logfile.log

Do not forget to put the double quotes, if not the command will not show any result.

That's all :)


Credit to for below technique, you can find the original post here

An alternative way to achive above result is by using -w flag of grep. So, instead of using grep "\>" logfile.log, you can also use grep -w logfile.log

Friday, March 19, 2010

Running windows cmd from linux

To run windows cmd from linux box, there is one tool you could use, which is winexe. You can download the installer from here. There are 2 ways to install this tool:

1. Use the preinstalled version.
  • Download from here
  • Unpack the bz2 file: # bunzip2 winexe-static-081123.bz2
  • Change mod to allow execute: # chmod +x winexe-static-081123
  • Make soft link in your /usr/local/bin: # ln -s winexe-static-081123 /usr/local/bin/winexe

2. Compile from source
  • Install necessary packages (gcc, svn, *-devel....)
  • Get sources from here
  • Unpack the source file: # tar -xvjf winexe-source-081123.tar.bz2
  • Compile according to README file:
    • cd to unpacked tar.bz2 sources
    • ./
    • ./configure
    • make proto bin/winexe
  • Compiled file will be located in wmi/Samba/source/bin/winexe
  • Install winexe:
    install -s wmi/Samba/source/bin/winexe /usr/local/bin/winexe

To use it is very simple:

# winexe -U foo -W WORKGROUP -n FOO-PC // "cmd.exe"

where -U for username, -W for workgroup, -n for target machine netbios name, is the ip address of the target machine and cmd.exe is to start windows command prompt.
Once connected, you will get command prompt like below:

Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.


To quit, just type exit at the windows command prompt.

That's all :)

Monday, March 15, 2010

Logging your terminal activity

When typing on the terminal, sometimes we need to record what commands we have typed for later reference. Sure, we can simply copy the .bash_history file, but that file only shows what you have typed and not the result of the commands that you have typed. To do these kind of jobs, there are two applications that you can use:

1. script

To use script, simply run script before you start using your terminal

# script -f logfile.log

where -f is to flush output after each write, and logfile.log is the file to write whatever script has recorded.

After finish using script, simply type exit or logout to quit script

2. rootsh

Please install rootsh first if it is not installed. To use rootsh, run rootsh before start using your terminal similar to script

# rootsh -f logfile.log --no-syslog

where -f is to show which file will be used to record the session, in this case logfile.log and --no-syslog is to tell rootsh not to log to /var/log/messages. To quit from rootsh, type exit or logout. All the commands and output will be written to logfile.log.closed to show that rootsh has closed the session.

To view the output file of rootsh and script, more command can be used.

Wednesday, February 24, 2010

Additional repository for CentOS 5

Below are a few additional repositories that are available for CentOS 5:

1. dag wieers

2. elrepo


That's all :)

Friday, February 12, 2010

Upgrade ubuntu server from jaunty to karmic

To upgrade ubuntu server jaunty(9.04) to karmic(9.10):

1. Update repository
$ sudo apt-get update

2. Upgrade current package
$ sudo apt-get upgrade

3. Install update-manager-core and do-release-upgrade
$ sudo apt-get install update-manager-core do-release-upgrade

4. Run do-release-upgrade
$ sudo do-release-upgrade

5. Follow the instructions, and wait until complete :)

Thursday, February 11, 2010

Install webmin in solaris 10

1. Go to /usr/sfw/bin
# cd /usr/sfw/bin

2. run webminsetup
# ./webminsetup

3. Answer all the questions, press "Enter" every time for default setting though.

4. If using default setting, you can access your webmin using this url: https://localhost:10000

Wednesday, February 10, 2010

Add PATH in solaris 10

To add /usr/local/bin to PATH in solaris 10 permanently for root:

1. Edit /.profile
# vi /.profile

2. Append below items to the end of /.profile:
export PATH

3. Save and exit

4. Activate the changes by using .
# . /.profile

6. Test it out. You can see that /usr/local/bin is in your PATH already
# echo $PATH

To add the directory temporarily, you can use command "export" if you are using bash:

1. Check your shell
# echo $SHELL

2. export the directory to PATH
# export PATH=$PATH:/usr/local/bin

3. Test your new PATH using step no 6 as above
# echo $PATH

That's all :)

Tuesday, February 9, 2010

Installing chrome web browser on fedora 12

I will show 2 ways to install chrome on fedora 12

1st way

1. download rpm file from here. Choose the rpm file according to your OS architecture and click "Accept and Install"

2. Wait until the download finish, then install the rpm file
# rpm -Uvh google-chrome-beta_current_i386.rpm

3. By installing this rpm, a yum repository file will also be created in /etc/yum.repos.d with the name google-chrome.repo
# cat /etc/yum.repos.d/google-chrome.repo


2nd way

1. Create a repo file in /etc/yum.repos.d with the name chromium.repo
# vi /etc/yum.repos.d/chromium.repo

2. Copy and paste settings below into the newly created file
name=Chromium Test Packages

3. Save and quit vi

4. Install chromium
# yum install chromium


Note that by using the 2nd way, you will get later version of chrome compared to the 1st way

Friday, February 5, 2010

Caching-nameserver quick howto for centos 5.4

To setup caching-nameserver:

1. Install bind, bind-chroot and caching-nameserver (bind is the nameserver, bind-chroot is to make bind operate in chroot environment and caching-nameserver is the BIND default setting for caching nameserver)
# yum install bind bind-chroot caching-nameserver

2. All bind configuration files will be stored in /var/named/chroot because of the bind-chroot package. A file named "named.caching-nameserver.conf" will be created in /var/named/chroot/etc. Rename the file to "named.conf"
# cd /var/named/chroot/etc
# mv named.caching-nameserver.conf named.conf

3. Edit named.conf until it become like below and save:
options {
listen-on port 53 { any; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";

allow-query { any; };
allow-query-cache { any; };
logging {
channel default_debug {
file "data/";
severity dynamic;
view localhost_resolver {
match-clients { any; };
match-destinations { any; };
recursion yes;
include "/etc/named.rfc1912.zones";

4. Set /etc/resolv.conf to point to localhost
# echo "nameserver" > /etc/resolv.conf

5. Restart your nameserver
# /etc/init.d/named restart

Done :)

Sunday, January 31, 2010

Installing dimdim 4.5 on Centos 5.4 x86_64

Dimdim is a web meeting software. From "Dimdim lets anyone deliver synchronized live presentations, whiteboards and web pages and share their voice and video over the Internet - with no download required".

There are few versions of dimdim, and the one we are going to install is the open source edition.
The steps are:

1. Download dimdim rpm from here
You have to provide email
, first name and last name before you can download.
2. Once downloaded, unzip the file ( and you can find one dimdim rpm file for Centos 5.2, one readme file, one web meeting user guide and one web meeting server integration guide.
# unzip
3. Follow the installation guide in the Dimdim_SF_CentOS5.2_RPM_Readme_v4.5.txt file. After finish with all the pre-requisite check, proceed to installation process.
4. If you have error stating that you have failure in OS check, change your /etc/issue from 5.4 to 5.2
# sed -i 's/5.4/5.2/' /etc/issue
5. If you got an error in missing libpcre, install pcre
# yum install pcre
6. Once installed, open your browser and point your browser to http://localhost/dimdim
7. Start meeting using your newly installed dimdim :)

Monday, January 11, 2010

Setting virtual ip in centos

Virtual ip is an ip that bind to a physical ethernet card that already have physical ip address. To set virtual ip in centos, follow the below steps:

1. We will add virtual ip to eth0. Below is original configuration of /etc/sysconfig/network-scripts/ifcfg-eth0. ifcfg-eth0 is the original configuration file for eth0.
# vi /etc/sysconfig/network-scripts/ifcfg-eth0


2. Create new virtual configuration file by copying and editing(change IPADDR and remove HWADDR) the ifcfg-eth0 configuration file

# cd /etc/sysconfig/network-scripts
# cp ifcfg-eth0 ifcfg-eth0:0
# vi ifcfg-eth0:0


3. Restart network
# /etc/init.d/network restart

4. Check your new virtual ip using ifconfig
# ifconfig

Thursday, January 7, 2010

Using alias in bash

Alias is some kind of shortcut in command lines, and it can be really productive if you can alias all the long commands that you use to manage your linux system.


To permanently set alias "d=dmesg | tail" for user "abu"

1. Append "alias d=dmesg | tail" to the /home/abu/.bashrc
$ echo "alias 'd=/bin/dmesg | /usr/bin/tail'" >> /home/abu/.bashrc

2. Activate the change
$ . /home/abu/.bashrc

3. Test the new alias
$ d
[drm] LVDS-8: set mode 16
[drm] LVDS-8: set mode 17
[drm] LVDS-8: set mode 18
[drm] LVDS-8: set mode 19
[drm] LVDS-8: set mode 1b
[drm] LVDS-8: set mode 1d
[drm] LVDS-8: set mode 1e
[drm] LVDS-8: set mode 1f
[drm] LVDS-8: set mode 20
[drm] LVDS-8: set mode 21

To temporarily set alias, just use the alias command at the terminal

$ alias d='dmesg | tail'

To remove alias. you can either delete it from ~/.bashrc or use unalias command

$ unalias d

Tuesday, January 5, 2010

Continue stalled scp file transfer session

Stalled scp file transfer session will happen when the network connection is unstable. You can see the status of the session at the message shown at your stdout like below:

file1 3% 136MB 0.0KB/s - stalled -

To continue back the file transfer, you can use this command at a new terminal, but make sure both the server and client have rsync installed:

$ rsync --partial --progress --rsh=ssh username@server:/path/to/remote-file /path/to/local-file

For example, if the transfer of file1 is stalled for user abu:

$ rsync --partial --progress --rsh=ssh abu@master:/home/abu/file1 /home/abu/file1

The scp transfer process will continue transferring the file

file1 4% 136MB 300.0KB/s 2:03:17 ETA