Monday, February 23, 2009

Rebuild corrupted dbmail account

Symptoms of corrupted dbmail account are slow to open account and if manage to open account, it will take forever just to open the inbox. Here are the steps to rebuild back the account using joe's email account

1. You have to backup the the user's inbox. Use command "dbmail-export" to export mailbox to mbox file. For better management, export the mailbox to home folder.
# cd /home
# dbmail-export -u joe

2. A few mbox files will be generated depending on how many folders you have in your email. The mboxs will be placed in a folder named with your username, in this case, joe
#ls /home

3. Clear up the username mailbox using "dbmail-users". -e is for clearing mailbox
# dbmail-users -e joe

4. Delete the user. -d is for deleting user
# dbmail-users -d joe

5. Create back user. -a is for add user, -w for password, -p for password type and -s for aliases
# dbmail-users -a joe -w joe123456 -p md5 -s

6. Download dbmail tarball from here. Extract and you can see a script named mailbox2dbmail in contrib folder. Use that script to migrate back the mbox files to dbmail. For easy usage, copy the mailbox2dbmail script to /usr/local/bin. -u is for username, -t for type of input, -m for input filename and -b is for the name you want the mailbox to appear in your email
# cd /home/joe
# mailbox2dbmail -u joe -t mbox -m INBOX.mbox -b INBOX

7. Go to your joe's webmail and you can see the INBOX is already there. Repeat step 6 for all your mailboxes

Friday, February 20, 2009

CentOS/Fedora forgotten password

What to do if you forgot the password for your CentOS/Fedora/Redhat machine?? Here are some simple steps to change back the password by entering into single user mode of your machine provided you do not forgotten your grub password if you have set it ;)

  1. Reboot your machine
  2. Press 'Esc' key once grub starts loading
  3. Select your kernel press 'e' on one of the kernel to edit the kernel parameter
  4. Press 'e' on the line that starts with 'kernel /vmlinuz...'
  5. Append ''single" or "1" at the end of the line
  6. Press 'Enter'
  7. Press 'b' to boot from the appended kernel
  8. You are now in the single user mode of your linux machine once you get to the shell. You can now change the password of your account using command passwd
  9. Reboot back your machine normally
  10. You can now log in to your machine using your new password

Tuesday, February 17, 2009

DNS lookup

To find an ip address for a domain, we need to do dns lookup. A few tools available for us to use in linux, but in this article I will give brief explanation about 3 most famous tools of dns lookup, which are host, nslookup and dig. Usually if the commands are used without the optional nameserver, then the nameserver entries in /etc/resolv.conf will be used

To find ip address of a domain using host (nameserver is optional):

$ host
$ host

To find the domain that belongs to an ip address using host (nameserver is optional):

$ host
$ host

To find ip address of a domain using nslookup (nameserver is optional):

$ nslookup
$ nslookup

To find the domain that belongs to an ip address using nslookup (nameserver is optional):

$ nslookup
$ nslookup

nslookup also have interactive mode that you can access by simply typing
$ nslookup

To find ip address of a domain using dig (nameserver is optional):

$ dig @
$ dig

Thursday, February 5, 2009

Unmounting busy device

You have an external drive attached to your linux machine. Then after finishing all your job, you try to unmount it, a message come out saying the device is busy.

# umount /media/disk
umount: /media/disk: device is busy
umount: /media/disk: device is busy

So what could possibly the cause?

1. You are inside the disk. Check your working directory using pwd

# pwd

2. Some files are accessing the disk. Check list of open files using lsof

# lsof | grep /media/disk

3. Some processes areaccessing the disk. Use fuser to check

# fuser -m /media/disk

What to do?

1. For case 1, just go to another directory

# cd
# umount /media/disk

2. For case 2, check the files that are accessing the disk and kill it

# lsof | grep "/media/disk"
vim 2693 pingu cwd DIR 8,4 4096 73729 /media/disk
# kill -9 2693
# umount /media/disk

3. For case 3, find the process that accessing the disk and kill it

# fuser -m /media/disk
/media/disk: 2693

# ps -e | grep 2693
2693 pts/0 00:00:00 vim
# kill -9 2693
# umount /media/disk

4. For case no 3 also, you can use fuser -k to kill the process that bugging the disk directly (Thanx to mr. linuxmalaysia for the comment)

# fuser -k /media/disk
#umount /media/disk

Hope this will be useful