Wednesday, 1 July 2015

HP ServiceGuard command list

Recently, I'm doing more work on HP-UX and the HP ServiceGuard, a high-availability cluster software produced by HP that runs on HP-UX and Linux.

Here are the command that I frequently use. The list is not final, and I will keep updating it.

Halt cluster
cmhaltcl

Shutdown package
cmhaltpkg [package name]

Get the cluster config
cmquerycl -q [quorum server] -C /home/user/cmclconfig.ascii -n [node1] -n [node2]

Get the quorum server
cd /etc/cmcluster grep QS_HOST *

Apply configuration
cmapplyconf -v -C /etc/cmcluster/cmclconfig.ascii

Start cluster
cmruncl

Node join cluster
cmrunnode

Check cluster package
cmviewcl - view information about a high availability cluster

Bring up cluster
cmrunnode [node1] [node2] [node3] [node4]
    cmrunpkg

    cmhaltnode

    Thursday, 31 October 2013

    Howto: Calculate exponent or power in Bash

    I have been looking on how to calculate exponent or power in Bash, but most website or blog will show the calculation by using bc (a command line calculator)

    I prefer not to use bc in my script, as it is a dependency to another application.

    Luckily, I found this blog after searching the Internet for few hours. http://blog.sanctum.geek.nz/calculating-with-bash/

    In essence, if you want to calculate exponent or power in Bash, just use this notation:

    **

    Example:
    Gigabyte is 1024^3. In bash notation:

    gigabytes=$((bytes / (1024**3)))

    [user@server]$
    echo $((10737418240/(1024**3)))
    10


    Bear in mind that bash calculation only return round number.

    Happy scripting :)

    Thursday, 22 August 2013

    Howto: Extract all email address from Google Contacts

    Let's say you want to extract all email address from your contacts in Google Contacts, and export it somewhere else. Yes you can just export the CSV file, and then upload. The other service will do the import and cleanup for you. But, if you just want to share the email address, why give them other info that they are not suppose to have?

    OK. Here are the steps to only extract email address using command line. I'm using Cygwin, but it should be similar if you are using Linux or other Unix-based operating system.

    Follow this steps:

    1. Select Contacts in Gmail


    2. Your contacts will be shown. Click More > Export


    3. Select All Contacts and Google CSV format, then click Export


    4. Save the file somewhere. I save it in C:\google.csv . If you are using Cygwin, the file is accessible using the path \cygdrive\c\google.csv

    5. Now come the interesting part, to extract the email address. The data is separated by comma, and we don't really know which column holds the email address. So we must iterate all column, and extract anything that resembles an email address. Here is the command:

    $ grep @ google.csv | awk -F, '{for(i=1;i<=NF;i++) if ($i ~ /@.*\./) {printf "%s\n", $i};}' | awk -F" ::: " '{for (i=1;i<=NF;i++) {print $i};}' |sort |uniq

    6. Let's break the command apart

    7. grep @ google.csv

    This command will get line that contain "@" character. The result is lines that contain "@", with multiple column, separated by comma ","

    8. awk -F, '{for(i=1;i<=NF;i++) if ($i ~ /@.*\./) {printf "%s\n", $i};}'

    This command let awk know that the field separator is comma (-F,). It will loop through all the field (for(i=1;i<=NF;i++)). If that field match an email pattern ($i ~ /@.*\./), it will print that field.

    9. awk -F" ::: " '{for (i=1;i<=NF;i++) {print $i};}'

    Some of the field will have multiple email address separated by " ::: ", because it groups the email address together. This command will split the field using " ::: " separator (-F" ::: ") then loop through each field, and print each of them

    10. sort

    This command will sort the output

    11. uniq

    This command will remove any duplicates.

    12. In the end you will get a list of emails. But, you must understand that the output might not be 100% clean. Some of your contact might put their email with their name, or the note area of your contact might contain additional information that resembles email. You need to clean up your output, but the effort will be small.


    Thursday, 4 April 2013

    How To: Boot from USB drive even if your BIOS won't let you

    This post is a continuation from my post about How To: Easy CentOS 6.3 installation using USB thumb drive

    After I finished setting up the USB thumb drive, one of the machine that I'm going to install did not allow me to boot from USB, because the BIOS did not support that capability.

    As I'm not going to burn the CentOS 6.3 Installer ISO into a CD-RW, just for this machine, I searched the Internet to find solution to this problem. And I found it.

    The solution is called plopKexec. This software, when you boot from the CD drive, will search if there are any USB drive attached to the system, and will try to load the Linux bootloader from that drive.

    How to use it:

    1. Visit the URL http://www.plop.at/en/plopkexec.html
    2. Click on Download
    3. Dowload the plopkexec.iso file
    4. Burn the ISO file into CD-R or CD-RW
     On the computer that you want to install using USB drive
    1. Plug in your USB drive into any USB port
    2. Put the plopkexec CD into the CD drive
    3. Power on your computer
    4. The CD will boot, an the menu from your USB thumb drive will shown
    5. Select "Install or upgrade an existing system" and continue installing CentOS 6.3 as normal
    Here's the screenshot of plopkexec loading the GRUB menu from my USB thumb drive


    That's it.

    Simple way to solve your USB booting issue :)

    Please leave comment if this solution have helped you.

    Thanks.

    Thursday, 3 January 2013

    How To: Easy CentOS 6.3 installation using USB thumb drive

    Recently, I need to do CentOS 6.3 installation on two machine that could be 32-bit or 64-bit processor. I have downloaded the minimal install ISO for both architecture, but I thought it could be a waste to burn multiple CD-RW, just to use it maybe only once.

    Then, I search the Internet on the simplest and easiest way to install CentOS 6.3 by using USB thumb drive. After learning from few website, and facing some trouble, this post will teach you the simplest and easiest way.

    What you will require:
    1. Minimal install ISO for CentOS 6.3. Get it from your local mirror.
    2. USB thumb drive - must be bigger that the size of the ISO. For minimal install, 1GB is good enough.
    3. UNetbootin software - I download the Windows version, because my work laptop is Windows
    The instruction given here is by using Windows. If you use Linux, you need to find out how to format the USB thumb drive in FAT32

    How to do it:



    Format the USB thumb drive
    1. Plug your USB thumb drive into the USB port on your Windows laptop/PC
    2. Your USB thumb drive should be detected, or a pop-up will say that your USB thumb drive is not formatted.
    3. If detected, say drive F:, right click and select Format
    4. If you got pop-up in step 2, proceed with Format
    5. Select FAT32 as file system.
    6. Tick Quick Format as format option
    7. Click Start
    8. Your USB thumb drive will be formatted with FAT32

    Transfer ISO content to USB thumb drive using UNetbootin
    1. Download and launch UNetbootin
    2. Select Diskimage and click the ". . ." button. Find the ISO and click Open
    3. Make sure Type is USB drive and the Drive letter is what your Windows detect.
    4. Click OK
    5. Your ISO content will be copied to USB thumb drive
    It actually did not end here. If you proceed with installation by using the USB thumb drive, the installer will say that it cannot find the ISO image.

    Follow this instruction:
    1. Copy the ISO file that you use with UNetbootin to the root of the USB thumb drive, eg. the ISO file should be F:\CentOS-6.3-i386-minimal.iso


    Now, proceed to boot up the machine that you want to install with CentOS 6.3 with your USB thumb drive. Make sure the machine BIOS support booting up from USB.


    During installation, you will be asked where to find the installation image, select from hard disk.


    When asked for partition that hold the image, just select OK.

    That's it. If you have any issue, please leave a comment.

    Thanks :)

    Tuesday, 30 October 2012

    Putty, Xming, CentOS X Forwarding not working

    If you are using Putty to forward your X session on CentOS Linux, make sure you have this requirement.

    Putty

    Make sure Enable X11 Forwarding is enabled



    CentOS

    Make sure package xorg-x11-xauth is installed. This is very important

    Xming

    No special setting required.

    Monday, 3 October 2011

    How to to list all packages by size for RPM and DEB

    You might be experiencing an issue where you don't have enough space for "/" in your server. Usually, the biggest thing that consume the space is your software installed in the server.

    So, for sure you want to remove the biggest software package installed on the server to recover back the space.

    The question is, how do you list all packages installed and sort it by size?

    I found the answer from this website: http://www.pixelbeat.org/docs/packaging.html

    The command that you should use is:

    For RPM:
    rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1n

    For DEB:
    dpkg-query -W --showformat='${Installed-Size;10}\t${Package}\n' | sort -k1,1n

    That's all. Remove the package by using Yum or Aptitude so that they can automatically find the correct dependencies for the removed package.

    Friday, 26 August 2011

    Check machine firewall if you are configuring network firewall

    I have wasted 2 days of my time trying to figure out what is really happening with my firewall config. The story is like this. I tried to configure a 3 NIC firewall machine for my office using Shorewall. For the DMZ zone, I put a test machine with Apache HTTPD installed to test if I can connect to it. With example from this site: http://www.shorewall.net/three-interface.htm . I can have my laptop in the local area to surf the Internet by configuring NAT/MASQ. I can SSH to the test web server, I can ping the server, but what really bugging me is that I cannot access the test web page hosted on the server.

    When I tried to connect from firewall to the web server in DMZ by using links/elinks, the application returned error "No route to host". Weird. I tried to check my routing table, and search the Internet for clue. Tried to play around with default gateway for the DMZ, but in the end, I still cannot connect to the web server.

    I even scrapped the whole thing and start again from scratch by following the example from this website: http://wiki.debian.org/HowTo/shorewall . Still cannot access.

    Then, while searching for solution on the Internet again, I found a forum that ask a poster whether the firewall on the machine itself is turned on. That struck me like lightning. I straight away SSH to the web server in the DMZ and issue the command "service iptables stop".

    Going back to my laptop and hit refresh in the web browser, voila!! The page is there!!

    I slapped my forehead 3 times for this silly mistake :D

    So, moral of the story, if you are configuring firewall for your network, make sure you turn off firewall on the machine so that you are not being fooled into thinking that your firewall configuration is problematic.

    2 day wasted, but really priceless experienced learned :)

    By the way, Shorewall really rocks :)

    Tuesday, 2 August 2011

    SSH reverse tunnel one way connection with HTTP proxy

    Wow..  the title is so long. But I think I need to title this post like that so that Google or other search engine can find it easily.

    Now, let's proceed with the blog post.

    Consider this scenario:
    • You need to connect to a CentOS Linux server on your customer's data center
    • The server outgoing connection is blocked by external firewall beyond your control, which means you cannot SSH to other server on the Internet
    • You need to update the software installed on the server by using Yum
    • You are connected to the CentOS Linux server by using Windows desktop and Putty
    How are you going to solve the issue?

    Most solution on the Internet shows the SSH reverse tunnel method with the assumption that you can SSH to external server on the Internet, and use that tunnel to forward whatever port that you want to use. That might not always be the case.

    This is the solution that I have created that will show you how to solve the scenario above. It will require:
    1. Windows desktop
    2. Putty SSH client
    3. AnalogX proxy
    The idea is to create port 8080 on CentOS Linux server, that will be forwarded to the Windows desktop on port 6588. AnalogX will use the port 6588 to proxy the Internet connection on the Windows desktop.

    So, how to configure this stuff?

    1. Configure Putty

    Launch your Putty SSH client and click Session. Fill in your CentOS Linux server domain name or IP address. Make sure the port is correct.



    Now, click Tunnels under SSH under Connection. Fill in the information as in the image below. Make sure you select the Remote option. Click Add.


    After you click Add, your setting will be like this image.


    Now, click Open, and login to the server as root. If you run the command
    # netstat -nap |grep 8080

    you will found out that port 8080 is available on the server and in LISTEN mode, as shown in the image below.


    Left it there for a moment, while we setup the AnalogX proxy.


    2. AnalogX proxy

    AnalogX proxy is a freeware simple proxy software for Windows. You can download the software from its website at http://analogx.com/contents/download/Network/proxy/Freeware.htm

    Install the software as normal, and launch it after installation. You will see the AnalogX proxy icon on your Windows taskbar.


    Right click the icon, and click Configure. You will be shown the configuration as below. Make sure at least HTTP is ON.


    With AnalogX proxy running, you have establish outgoing connection from the Linux server to your desktop by using SSH tunnel.
    3. Configure Yum

    Now, in order to update the software installed on the Linux server, Yum must know how to connect to the Yum repositories that contain updates.

    Luckily, Yum only need to know the http proxy available, and an update can be performed easily.

    To make Yum use http proxy, type this command as root

    # export http_proxy=http://localhost:8080

    This command will configure system-wide proxy setting for the Linux server.

    When you issue the command

    # yum check-update

    Yum will use the http proxy connection that you have created through SSH tunnel from your Windows desktop, to the AnalogX proxy running on your desktop, to the Internet.


    Conclusion
    The solution that I have created above will help you to achieve your goal to update the CentOS Linux server with the latest update. This setup will also work for apt tools in Debian and Debian-derivatives

    If you are using Linux desktop, you can change AnalogX proxy with 3proxy, Squid, or nginx. The SSH remote port can be configured by using simple SSH options. The details is for you to figure out ;)

    Friday, 28 January 2011

    Dan Pink on the surprising science of motivation

    This talk is good and so true, you need to watch it yourself. And then try it at your organization (if you are the boss), or promote it at your organization (if you are the worker)

    http://www.ted.com/talks/lang/eng/dan_pink_on_motivation.html

    Friday, 1 October 2010

    Several important Bash shortcut

    I've been using Bash a lot, and sometimes when typing long command line, having to press the arrow button multiple times to go to the first character is very tiring.

    This are few important shortcut that I start to use:

    Ctrl + a - Jump to the start of the line
    Ctrl + e - Jump to the end of the line
    Alt + d - Delete word
    Alt + f - Move forward a word, where a word is composed of letters and digits

    Alt + b - Move backward a word

    More info from this blogpost : http://linuxhelp.blogspot.com/2005/08/bash-shell-shortcuts.html

    Or from Bash Reference Manual regarding Readline Movement : http://www.gnu.org/software/bash/manual/bashref.html#Readline-Movement-Commands

    Thursday, 24 June 2010

    Looking for undergraduates that interested to learn and practicing PHP and MySQL

    Hi all,

    I'm looking for undergraduates in IPTA/IPTS, preferably between 1st year to 3rd year, that are interested to learn and practice PHP and MySQL.

    The undergraduates should be studying around Klang Valley for logistics reason.

    The requirement is, they will be assigned a task or mini project, and they will learn on their own what ever topic needed in PHP and MySQL in order to complete the task or the mini project.

    If they manage to complete the mini project, which I expected to be around 1 month depending on complexity, they will be rewarded with cash. The amount will be informed before the task start.

    During the project, I will be available for consultation, and I expect the candidate to have a face-to-face discussion about the project progress with me, preferably once a week.

    At the end of the project, the whole code and documentation will become my intellectual property, but they are allowed to quote the project name and knowledge that they have gained for their own curricular vitae.

    If you an undergraduate and you are interested, please send your curricular vitae to my email at sharuzzaman@gmail.com

    If you know any undergraduate that would be interested, please forward them this info, and ask them to send their curricular vitae to my email above.

    Thanks.

    Thursday, 20 May 2010

    Suppressing getopts unknown option error message in ksh

    I'm writing a new ksh (Korn Shell) script today. Before this, I only write bash script, and I believe the knowledge that I gain today will be valuable to a lot of people.

    When I'm trying to use getopts in ksh, the script complain that there are "unknown option" after I put some option that are not available.

    Let see the code, and the way it respond.

    user@computer $ cat -n getopts.sh
         1  #!/bin/ksh
         2
         3  while getopts "h" arg
         4  do
         5    case $arg in
         6      h)
         7        echo "Help!"
         8        ;;
         9      ?)
        10        echo "Others"
        11        ;;
        12    esac
        13  done

    user@computer $ ./getopts.sh -h
    Help!

    user@computer $ ./getopts.sh -a
    ./getopts.sh[13]: -a: unknown option
    Others

    I expect when I put the option "-a", the script will just output "Others" without any issue. But it does not. Something is not correct with the code.

    Searching the Internet for answer, I found this very informative site: http://aplawrence.com/Unix/getopts.html

    At first read, the site did not specifically mentioned that you have to put leading ":" to suppress the errors, but after reading it the second time, I got the idea, especially after reading this word:

    The leading ":" works like it does in "getopt" to suppress errors

    So, to solve the issue, some minor modification has to be done to the script above. Let see the updated script and the output after the modification.

    user@computer $ cat -n getopts.sh
         1  #!/bin/ksh
         2
         3  while getopts ":h" arg
         4  do
         5    case $arg in
         6      h)
         7        echo "Help!"
         8        ;;
         9      ?)
        10        echo "Others"
        11        ;;
        12    esac
        13  done

    user@computer $ ./getopts.sh -h
    Help!
     
    user@computer $ ./getopts.sh -a
    Others


    Voila! The problem solved :)

    Happy scripting :)

    Monday, 29 March 2010

    Alternative way to grep IP address accurately from log file

    This post is an alternative way to grep IP address from log file, as a reply for Hisham Mohd Aderis (linuxwave) post.

    Let say we have a log file that contain IP address as below

    $ cat ipadd.txt
    192.168.1.1
    192.168.1.10
    192.168.1.11
    192.168.1.100
    192.168.1.101

    If we use just grep to get 192.168.1.1, all the IP address will be returned. This is because the default setting for grep regular expression is greedy, which means that it will match anything that have full or part of the string that we are searching for.

    $ grep 192.168.1.1 ipadd.txt
    192.168.1.1
    192.168.1.10
    192.168.1.11
    192.168.1.100
    192.168.1.101

    But, grep got a "-w" switch that will match only the word that we are looking for.

           -w, --word-regexp
                  Select  only  those  lines  containing  matches  that form whole
                  words.  The test is that the matching substring must  either  be
                  at  the  beginning  of  the  line,  or  preceded  by  a non-word
                  constituent character.  Similarly, it must be either at the  end
                  of  the  line  or  followed by a non-word constituent character.
                  Word-constituent  characters  are  letters,  digits,   and   the
                  underscore.

    So, to match an IP address correctly, we should use the command as below

    $ grep -w 192.168.1.1 ipadd.txt
    192.168.1.1

    $ grep -w 192.168.1.10 ipadd.txt
    192.168.1.10

    As shown, the IP address will be matched to the one that we are looking for.

    Happy scripting. :)

    Monday, 4 January 2010

    My 2010 resolution

    A lot of people failed to achieve their last year resolution. I did not make any resolution last year, but I believe I made a lot of progress last year. New job, better salary, Suse Linux Professional 10 certification, ITIL v3 Foundation certification... quite an achievement I would say.

    Most people also think, resolution should be made on new year day, but I think, resolution should be made year round. In Islam, there is a concept of daily muhasabah before you goes to sleep, to think what you have done good today, what you have not done what you should be doing, what bad thing that you have done and what you should do tomorrow to make sure it is a better day than yesterday, and you become a better person than yesterday.

    So, if you still don't have you 2010 resolution, read this article first: New Year's Resolutions Experiment

    In essence, the article mention that
    Men were significantly more likely to succeed when asked to engage in either goal setting (e.g., instead of trying to lose weight in general, aiming to lose a pound each week), or focusing on the rewards associated with achieving their goal (e.g., being more attractive to the opposite sex).

    Women were more successful when they told their friends and family about their resolution, or were encouraged to be especially resilient and not to give up because they had reverted to the old habits (e.g., if dieting, treating a chocolate binge as a temporary setback rather than as failure).

    It also said that it is better to have only one resolution, and the resolution is specific.

    For 2010, I have several resolution, but I will try my best to achieve it for the length of the year. Here goes:

    1. Be a Red Hat Certified Engineer
    2. Learn Python, become a master, and get certified.
    3. Be a Debian Developer

    Resolution number 3 will be very tough, but I know I should start doing something to become a Debian Developer. Let see if I can achieve what I have planned here by the end of the year :)


    Thursday, 17 December 2009

    Basic and fundamental knowledge

    I was recently asked with some basic and fundamental question, directly related to Linux system administration job. When you are already a senior engineer, most of the time you will forget about the fundamental, or don't really care about it. But truth is, you still need to know about it, because it is so fundamental. People will judge you with this basic information to know that if you are really knowledgeable and your level is what you really say you are at. I'm not able to answer all the question satisfactorily, and feel somewhat ashamed about it.

    Let's learn it together.


    1. What is the difference between a network hub and a network switch? 

    When I search Google for the answer, I believe this site put it very nicely. Take a look at http://www.duxcw.com/faq/network/hubsw.htm . In essence:
    • Hub repeats the packet it receive on one port to the other port available
    • The bandwidth is shared across all the ports. If the hub is 10Mbps, with 5 ports, then each port can only transfer at max 2Mbps
    • Switch divides the network into multiple segment thus a pair of ports can communicate without affecting other pair of ports
    • Switch maintains a table of destination address and its port, so when a packet arrives, it will send the packet to the correct port
    • The bandwidth of the port is dedicated. If the switch is 10Mbps, with 5 ports, when port 1 connect to port 2, the bandwidth is 10Mbps for that instance, and when port 3 connect to port 4, the bandwidth is also 10Mbps for that instance

    2. How many bit are there in a MAC address?

    I cannot answer this question correctly. The answer is 48 bit. This site provides the information: http://compnetworking.about.com/od/networkprotocolsip/l/aa062202a.htm .  In essence:
    • MAC address have 12 digit hexadecimal number
    • 1 hex = 4 bit, thus 12 hex = 48 bit
    • Hex symbol is 0123456789ABCDEF
    • The first 6 hex digit represent the manufacturer

    3. What is the difference between TCP and UDP?

    Wikipedia have the answer: http://en.wikipedia.org/wiki/User_Datagram_Protocol#Comparison_of_UDP_and_TCP
    • TCP is Transmission Control Protocol
    • TCP is connection oriented link
    • When a machine send a TCP packet, the receiving machine have to send back acknowledgment packet when it arrive
    • If sending machine fail to get the acknowledgment after certain time period, the packet will be resend again.
    • Example of TCP usage is between web server and web browser
    • UDP is User Datagram Protocol
    • UDP never guarantees that a packet will arrive at destination
    • When a machine send a UDP packet, it is not expecting acknowledgement from the receiving machine.
    • Example of UDP usage is audio streaming, and DNS

    3. What information are available in TCP packet? Name some of them.
    • Source address
    • Destination address
    • Checksum

    4. What flag are available in TCP packet? Name some of them.

    I also cannot answer this question correctly. The answer are:
    • SYN
    • ACK


    5. When you execute "uptime" command, there are 3 numbers at the end of the line. What are they?

    Answer here: http://linux.die.net/man/1/uptime . The 3 numbers are load averages for the past 1, 5, and 15 minutes.


    6. What is the meaning of the load average number?

    Here is the answer: http://www.lifeaftercoffee.com/2006/03/13/unix-load-averages-explained/ . It means "the average sum of the number of processes waiting in the run-queue plus the number currently executing over 1, 5, and 15 minute time periods."


    7. How do you know that the server is busy from the number?

    The best answer probably from this site: http://www.teamquest.com/resources/gunther/display/5/index.htm . For this question, I answered if the number is 2 or bigger, then the server is busy or under heavy load. This is relative, and you will know from experience handling Linux or Unix machines.


    8. What happen when the machine is busy?

    I answered, the most noticeable clue is that you have trouble accessing the server remotely. When you SSH to the server, it will take a while before you are able to login. This is because the SSH connection is encrypted and the server will need to decrypt the data before able to give you access. Encryption and decryption takes big amount of CPU cycle, and if the machine is already busy, you will see it will take some time before you are able to login.

    Other than that, if the machine have small amount of memory, you will see a lot of disk activity, because the OS is swapping the application that resides in memory, but is not executed, to the disk to make way for application that have higher priority.


    9. How do you list processes running in the machine?

    Use the command "ps"



    10. How do you terminate a misbehaving application?

    Use the command "kill -9 <appname>". The number 9 is sending the SIGKILL signal. To terminate application with the same name, use "pkill <appname>"


    11. What other signal available?

    This site summarize it: http://linux.about.com/od/commands/l/blcmdl7_signal.htm . Other signal available is SIGHUP and SIGTERM. I answered SIGHUP is to restart an application, but most information in Internet said that SIGHUP is to re-read configuration file or to stop an application. You might need to search for more concrete answer.

    SIGTERM is terminate signal sent to application to stop it gracefully. When application receive a SIGTERM, it will do the necessary process to make sure it is stopped cleanly.


    12. What is the difference between SIGKILL and SIGTERM?

    SIGTERM is a graceful termination signal. The application that receive the signal will try its best to stop or notify any dependency, and then terminating itself. For example, if a parent process got SIGTERM, and it has few child process, the parent process will notify the child process that the parent is being terminated, and the parent might also send SIGTERM to the child to terminate them before terminating itself. SIGTERM can be ignored if the application was programmed to do so.

    For SIGKILL, the application will be directly terminated by the OS. No information will be sent to any dependencies of the program. If a program have a child process, that child process might become orphan or zombie because its parent has been killed and it has no clue on what to do next. This kind of issue might cause further instability to the server if the server is already have some issue.


    13. Have you experienced application that will not terminate even after you send SIGKILL signal? How do you terminate such application?

    More info here: http://en.wikipedia.org/wiki/Zombie_process . That application is called zombie application. To find zombie application, use command "ps aux | grep Z", where the zombie application will have Z as its status. You cannot killed a zombie application because it is already dead. What I usually do is, if the zombie process have a parent process, I will terminate the parent process, where most of the time the zombie process will terminate because its dependency to its parent has been terminated.

    But, there are cases that, when you terminate the parent process of the zombie, the zombie will then use process with PID 1 as its parent. Process with PID 1 is the init process, and it is the first process to run when the server starts. If this happen, you have no other way to kill the zombie other than rebooting the server.


    14. What actually pkill command do?

    pkill will list the PID of the process that have the name as specified, then will terminate the application one by one. The default signal sent is SIGTERM.


    That's all. I have learned quite a lot after this event. Hopefully this post will be helpful to someone out there.
    Got comment? Let me know. :)

    Tuesday, 10 November 2009

    Tracing bitmap in Inkscape

    During BOF session in MyGOSSCON 2009, Nuhaa a.k.a cawanpink representing FOSSchix.my, was presenting on how to use Inkscape to produce graphic images. After her presentation, I inform her that Inkscape has the capability to trace bitmap into vector graphic, so that if you want to scale the image, it will not become blur (when scale down) or become boxy (when scale up). I guide her the step to produce the vector image. I believe a lot of Inkscape user also did not know much about this capability. This post will explain the step.

    Step:
    1. Search Google Images for the image that you want to trace. Usually you would like to trace logo to be use somewhere else. When you search for image, try to find big or medium size image. In this example, I want to search for 1Malaysia logo.





    2. Download the logo to your computer. Here is the logo that I got.





    3. Open the bitmap image in Inkscape.





    4. Press Ctrl+A to select all the image. Then select the menu Path > Trace Bitmaps





    5. Dialog option will be displayed. Select the option Colors, Stack scans and Remove background. After that, click the Update button. You will see a preview of the trace. If you are happy with the preview, click OK





    6. The vector image will be available on top of the bitmap image. If you select the logo, you can move it around. In the picture below, I move the vector image to the right.





    7. You can delete the bitmap image then move back the vector image to the canvas. After that you can do anything with the vector image. Here, I made a clone of the image, then scale it down. The image is still sharp because it is a vector.


    That's all. You can save the vector image to SVG format if you want to edit it again in the future.

    Happy drawing! :)

    Thursday, 5 November 2009

    Programming in PostScript

    I have found my new craze! It is programming in PostScript! :D

    What is PostScript, you may ask? PostScript is a programming language optimized to print graphic and text. You can think it as a page description language, much like HTML is the document description language for the web.

    It all started when Najmi posted to MyPenguin99 mailing list about the powerfulness of Python to generate a PDF file. It is called Simson Garfinkel's Notepaper Generator. Upon closer inspection, I found out that it is not the Python that is powerful, but it is the PostScript language that is powerful that you can program your paper document to look like what you want it to be.

    The Python script is just a script that help you to either enable or disable a feature, change the owner of the paper, and generate the calendar to be put into the PostScript file. From the PostScript file, it is converted to PDF by using ps2pdf command line program.

    Suddenly, a question pops in my head. How hard it is to hand-coded a Postscript file? I have never program a PostScript before and don't know the answer. But I'm going to find out.

    Few years back when I'm an electronic engineering student, graph paper is one of my tools of the trade. Back then, when I'm running out of graph paper, I have to buy a graph paper pad with 10 sheet in it, even though I might only need a single sheet to complete my assignment.

    So, to challenge myself for the PostScript programming, I'm planning to create a 1 mm by 1 mm grid that will occupy an A4 paper, with about 1 inch border from the edge of the paper. That should be easy, I think.

    And actually, it is easy! I just learned PostScript in 2 days from information available on the Internet, and also found a PDF file from Adobe called "PostScript Language Tutorial & Cookbook". It contains all the command that you need to know about programming in PostScript. Search Google using the keyword "postscript tutorial".

    PostScript is not hard. It is stack-based in the same manner as RPN calculator. And this is easy for me because I program Motorola microcontroller using stack-based instruction in assembly language during my university days :)

    The result of the PostScript file can be viewed without having to print it out, by using GSview for Windows. You can also use Evince for Gnome or Okular for KDE. The PostScript file can be converted to PDF file
     by using PDFCreator in Windows, or ps2pdf command line in Unix/Linux/BSD.

    Below are two screenshot of GSview, one viewing the A4 paper in whole, and the other zooming the paper to its width.





    Get the source from the URL below. Now I can start to create my own GTD paper organizer. :D

    Enjoy! :)

    http://sharuzzaman.tripod.com/file/graph.ps

    Tuesday, 3 June 2008

    Having fun with Apache reverse proxy

    Today I managed to configure an Apache reverse proxy. Why do I need a reverse proxy? Consider this scenario:
    1. I got 2 public IP: 192.0.2.1 and 192.0.2.2
    2. Firewall hold all the public IP via IP aliasing (eg. eth0:1 = 192.168.0.2.1, eth0:2 = 192.0.2.2)
    3. I'm running authoritative DNS on my firewall
    4. I initially have 2 webserver inside firewall, with IP address 172.16.0.1 (xavier) and 172.16.0.2 (magneto)
    5. My domain name is example.com
    6. Subdomain www.example.com is served by xavier, and webmail.example.com is served by magneto
    7. DNS was configured so that www.example.com will be resolved to public IP 192.0.2.1 and webmail.example.com will be resolved to public IP 192.0.2.2
    8. IPTables was used to redirect port 80 from public IP to its corresponding private IP (eg. 192.0.2.1 -> 172.16.0.1)
    9. All webserver must run on port 80 and is using Apache 2.x.
    Now, I want to add another web server with IP address 172.16.0.3 (cyclops), that should serve the subdomain dev.example.com

    How can I do that? I only have 2 public IP! I cannot use other non-standard port!

    The solution?

    It comes in the mixture of DNS and Apache reverse proxy.

    On DNS:
    - add subdomain dev.example.com to resolve to public IP 192.0.2.1
    - restart DNS service

    On Apache 2.x web server in xavier (172.16.0.1)
    - make sure mod_proxy is enabled in /etc/httpd.conf
    - create a new file in /etc/httpd/conf.d/ (eg. dev.example.com.conf)
    - in the file, put the following directives


    <VirtualHost 172.16.0.1>
    ProxyPreserveHost On
    ProxyPass / http://172.16.0.3/
    ProxyPassReverse / http://172.16.0.3/
    ServerName dev.example.com
    ProxyRequests Off

    <Proxy *>
    Order deny,allow
    Allow from all
    </Proxy>
    </VirtualHost>


    - restart Apache service

    That's it. Try to surf the new subdomain http://dev.example.com using anonymous surfing site (eg. http://anonymouse.org/) and you should be presented with the content of cyclops web server.

    How does it work?

    - The subdomain dev.example.com will be resolved to public IP 192.0.2.1 by our DNS server.
    - Request for port 80 to dev.example.com will be forwarded to the Apache web server running on xavier (172.16.0.1)
    - On xavier, the VirtualHost directive is aware that it is serving for subdomain dev.example.com
    - But that directive contains a ProxyPass instruction to pass all request (hence "/" or root directory) to the server cyclops (172.16.0.3)
    - It also have the directive ProxyPassReverse to pass everything received from cyclops back to the client as if the root (/) is on the server
    - Other directive is left as an exercise to the reader to find out

    Other usage of Apache reverse proxy

    - Reverse proxy can be used to mask/map port 80 to webserver hosted on non-standard port (eg. 8080) **I believe IPtables port manipulation can achieve the same result

    - Shield not-so-secure I*S web server running on not-secure-at-all W*s host.
    This will not protect against SQL injection or other web-based attacks. It can help to shield the server from OS related attacks because client will see that the webserver is Apache running on Linux, not I*S running on W*s. You might want to take a look at mod_security for added protection


    Have fun :)

    Friday, 9 May 2008

    Using shell script to solve problem

    I'm translating KDE4 to Malay language, but when I'm in the kdebase folder, I cannot determine which files that should be translated, and also have been neglected for some time. While I can check each file manually to determine its translation status, I'm really lazy to do the same thing again and again.

    By using shell script, I can automate the task and become more lazier :P

    Requirement:
    List all po files according to date, older to newer, and only contain fuzzy or untranslated message.

    Solution:

    sharuzzaman@debian:/kde4-stable/kdebase$ cat -n list.sh
    1 #!/bin/bash
    2
    3 for file in `ls -tr *.po`
    4 do
    5 output=`msgfmt -o /dev/null --statistics $file 2>&1`
    6 fuzzyuntranslate=`echo $output | grep -e "fuzzy\|untranslated"`
    7 if [ "$fuzzyuntranslate" != "" ]
    8 then
    9 echo $file
    10 fi
    11 done


    Let's take a look at the solution, line by line.

    Line 1: Declare the script as a Bash script

    Line 2: Blank space for clarity

    Line 3: This is the starting point of the "for" loop. The command "ls -tr *.po" will list all po files according to date and reversed, which means older to newer. We quote the command in backtick `` because we want the command to be executed, and the output to become the array of file name for variable "file"

    Line 4: The "do" is the part in the "for" loop that we process our list of files.

    Line 5: Execute the command "msgfmt -o /dev/null --statistics $file 2>&1" and put the result in variable "output". The 2>&1 redirection is required because the output for msgfmt is printed on stderr, not stdout, so we redirect it to stdout in order to capture it.

    Line 6: Echo back the variable "output" and check if it contain the word "fuzzy" or "untranslated" using grep. Put the result in variable "fuzzyuntranslated". If the variable "output" did not contain the word that we search for, the variable "fuzzyuntranslated" will be blank. We use "grep -e" because we have regular expression "|" that carry the meaning "or" on the command

    Line 7: Check if the variable "fuzzyuntranslated" is not blank (which means either contain fuzzy, untranslated, or both fuzzy and untranslated)

    Line 8: Then

    Line 9: Print out the file name that match our requirement.

    Line 10: Close the if block with fi

    Line 11: Close the do block with done


    That's it. We have completed our requirement.

    The output should be a long list of filename. I can pipe it to "head" to get only the first 10 line of the filename.

    sharuzzaman@debian:/kde4-stable/kdebase$ ./list.sh |head
    kdmgreet.po
    nsplugin.po
    kdialog.po
    kdebugdialog.po
    kcmkwindecoration.po
    kcmusb.po
    kcmstyle.po
    kdmconfig.po
    kcmscreensaver.po
    khtmlkttsd.po


    Happy scripting :)