Wednesday, April 27, 2011

A Nice Blog About Blogger

There is a nice blog about Blogspot. If you use Blogger as free blog, you should check this blog: There are so many resource about styling, monetizing, and optimizing your blogspot space.

Let's check it out and enjoy!

How to Tunnel SSH via HTTP Proxy

I have to access ssh server but there is http proxy when I want to go to internet. How can I tunnel ssh via http proxy? Here are the way to do it:

# Download corkscrew. It is easy tool for tunneling SSH through HTTP proxies

# Extract corkscrew then configure and install it
tar -xzvf corkscrew.tar.gz
cd corkscrew
make install
# Create ~/.ssh/proxyauth file and set authentication for http proxy server
# Open ~/.ssh/config file. Add proxy server ip address and its authentication in proxyauth file like this:
Host *
ProxyCommand corkscrew proxy_ip_address proxy_port %h %p ~/.ssh/proxyauth
# Try to access your server via ssh
And it's all done. Enjoy!

Monday, April 18, 2011

Apache Rewrite Modul Problems in Linux Ubuntu

I often have a problem with rewrite modul in Apache. When you have the same problem like me, you should check:

# RewriteBase syntax in .htaccess

# "Allow all" option in /etc/apache2/sites-enabled directory. Here are the example of 000-default file in sites-enabled directory (in tag Directory "/var/www/somedir"):
   Order allow,deny
Allow from all
AllowOverride All

# Is .htaccess file executable?

# Make sure rewrite module is loaded in Apache. When this module successfully loaded, it will appear in mods-enabled directory as rewrite.load file. You can load them by issuing:
sudo a2enmod rewrite
Just double check them. Enjoy!

Wednesday, April 13, 2011

First Timer RabbitVCS Subversion Client

After setting proxy in RabbitVCS, I have a folder that contains app files to be versioned. How can we add these files to our subversion server?

# Right click in the folder, choose Checkout

# Set subversion servers, for example:

# Set directory to be versioned

# Click OK or Finish.

Then we can submit all of app files by right-clicking the folder and choose Commit. Select or deselect any files you want to Commit. Wait a moment and you're done versioning your app files for the first time. Enjoy!

How to Set Proxy in RabbitVCS Subversion Client

I use RabbitVCS as subversion client in my little Ubuntu box. Since I should work behind proxy, I have set up proxy username and password in RabbitVCS. Don't forget to be root to configure :).

# Go to /etc/subversion
cd /etc/subversion
# There are two files: servers and config. Open servers file
vi servers
# Find [global] section and set proxy host, username, and password
http-proxy-host = proxy_ip_address
http-proxy-port = proxy_port
http-proxy-username = username
http-proxy-password = password
And you're ready to version your apps. Enjoy!

Monday, April 11, 2011

How to Execute Wget Behind Proxy

Two days getting headache because of working behind proxy, here is one of the result: wget command with using proxy option enabled.
wget --proxy-user=username --proxy-passwd=password

Don't forget to set your proxy first. Enjoy!

Curl Using Proxy in Linux Console

Going crazy using Linux console? Here is how to use curl in console behind proxy.
curl -x proxy_ip_address:port -U username:password


Sunday, April 10, 2011

How Many Watt Consumed in Ubuntu Laptop?

Yay... we will estimate how many watt consumed in Ubuntu laptop using data from ACPI interface. We have measured voltage and current, getting exact value of them, trying to make a simple shell script, and installing calculator package in console.
By putting all of these stuffs altogether, we will estimate how many power used by our lovely Ubuntu box.

# Make a shell script to cat voltage and ampere usage
cat /proc/acpi/battery/C1AC/state | grep "present voltage" |
awk '{print $3}'
cat /proc/acpi/battery/C1AC/state | grep "present rate" |
awk '{print $3}'
# Make two variables to store voltage and ampere value
volt=`cat /proc/acpi/battery/C1AC/state | grep "present voltage" |
awk '{print $3}'`
ampere=`cat /proc/acpi/battery/C1AC/state | grep "present rate" |
awk '{print $3}'`
# Divide variable volt and ampere by 1000 because it still in mV or mA unit
volt=`echo "scale=3;$volt/1000"|bc`
ampere=`echo "scale=3;$ampere/1000"|bc`
Parameter scale is used to set precision. If we set them to 3, then we will get three decimal places precision.

# Measure the power by simply multiply voltage and current consumed
power=`echo "scale=3;$v*$a"|bc`
# And the full shell script is illustrated below:
volt=`cat /proc/acpi/battery/C1AC/state | grep "present voltage" |
awk '{print $3}'`
ampere=`cat /proc/acpi/battery/C1AC/state | grep "present rate" |
awk '{print $3}'`
volt=`echo "scale=3;$volt/1000"|bc`
ampere=`echo "scale=3;$ampere/1000"|bc`
echo "Present voltage: " $volt "Volt"
echo "Present current: " $ampere "Ampere"
power=`echo "scale=3;$volt*$ampere"|bc`
echo "Present power :" $power "Watt"
# And it will give us a message like this:
Present voltage:  16.285 Volt
Present current: 1.507 Ampere
Present power : 24.541 Watt

This shell script has been tested in Ubuntu Lucid Lynx 10.04 and it works well. Enjoy!

[Linux Ubuntu] Getting Exact Value of Voltage and Current

We are now one step closer to measuring power process. In the previous explanation, we have got voltage and current value but it still has some obstacles. I mean, there are string "present voltage:" and "present rate" in voltage and current value, respectively. How can we remove them? We employ grep to get certain line and we can use awk get certain column of one line output.
cat /proc/acpi/battery/C1AC/state | grep "present voltage" |
awk '{print $3}'

cat /proc/acpi/battery/C1AC/state | grep "present rate" |
awk '{print $3}'
$3 in awk means it only prints the third column. The value of first column is string "present" and the second one is "voltage" or "rate" in current value. This command will print the exact value only without obstacles. Enjoy!

How to Make a Shell Script in Linux?

Yeah, like you say, it's for newbie only :D. We will make a shell script to display voltage in mV and current in mA like I post before. Shell script can contain one or more lines of instruction usually issued in Terminal.

# Open your editor (I always choose vi) type:
cat /proc/acpi/battery/C1AC/state | grep "present voltage"
cat /proc/acpi/battery/C1AC/state | grep "present rate"
# Don't forget to replace "C1AC" with your own battery type

# Save these shell script, for example,

# Change the mode of file so that it can be executed
chmod +x
# Run this script by typing this instruction in your Terminal:
# The output will look like this:
present voltage:         16778 mV
present rate: 702 mA
Shell script will simplify our life. Believe me and enjoy!

How Many Volt Consumed by Ubuntu Laptop?

Now we will observe how many watt consumed by Ubuntu laptop. Similar with how to check current (in ampere) consumed, we will only replace the grep command.

# Goto /proc/acpi/battery directory and go to directory name based on your battery type (i.e. C1AC)
cd /proc/acpi/battery/C1AC
# Cat the content of state file and grep only the voltage
cat state | grep "present voltage"
# We will get output like this:
present voltage:         16410 mV

The voltage consumed is shown in mV. Enjoy!

How Many Ampere Consumed by Ubuntu Laptop?

We can monitor how many ampere consumed by our Ubuntu laptop. Unfortunately, we still can't do them in Ubuntu desktop. ACPI interface will be used to employ this technique.

# Goto /proc/acpi/battery directory
cd /proc/acpi/battery
# There is only one directory and the name is different in accordance with laptop specifications. For example, my folder name is C1AC.
cd C1AC
# You will see three files: alarm, info, and state. Try to show the content of "state" file
cat state
# You will get a technical state about battery like shown here:
present:                 yes
capacity state: ok
charging state: charging
present rate: 1505 mA
remaining capacity: 840 mAh
present voltage: 16410 mV

# We only want to get ampere used, so just grep them
cat state | grep "present rate"
# The output is ampere present rate shown in mA
present rate:            1505 mA

We will use this technique to get power (in Watt) consumed by Ubuntu laptop. Enjoy!

Is There any Calculator in Terminal?

Yeah, absolutely. You can use bc package in Linux Ubuntu. This is an arbitrary precision calculator language. Or, we can just call it "bash calculator" (bc). Simply issue this command:
apt-get install bc
Of course you have to be a root when issuing it. Now we will try bc to perform simple arithmetic operation, such as:
echo 2+3 | bc
echo 2-3 | bc
echo 2*3 | bc
echo 6/2 | bc

Run them in terminal and you will get output: 5, -1, 6, and 2. We will use this calculator later in the next tutorial. Enjoy!

[Linux Ubuntu] How to Put Harakat or Vowel Marks in Arabic Keyboard Layout

Now, you are able to enable Arabic keyboard layout and write them in Linux Ubuntu. What about adding harakat or vowel marks in Arabic? Follow these steps:

# Write the word first. For example, word "Al 'Ilmu"


# We should put fatha in character " ا ". To do this, put cursor behind character " ا ".

# In the Arabic keyboard layout, fatha is placed in character Shift + Q. So, press Shift + َQ and you will get: " اَ "

# Now put the cursor behind character " ل " and add sukun mark by pressing Shift + X. You will get: اَلعلم

# Continue these steps until all of word is fulfilled with appropriate harakat (اَلْعِلْمُ). Enjoy!

How to Write Arabic in Linux Ubuntu

How to write Arabic in Linux Ubuntu? First, you should enable Arabic keyboard layout. The Arabic keyboard layout will look like this picture (click to enlarge):

arabic keyboard layout in ubuntu
# Then, open your favorite text editor. I prefer gedit (Applications*Accessories*gedit Text Editor)

# Click Keyboard Preferences (usually it is placed in top-right of desktop panel) and it will be switched from USA to Ara

# Type your word one by one based on Arabic keyboard layout. It will be connected automatically.

# Type Space key to separate one word to another.

It is easy, isn't it? Enjoy!

Saturday, April 9, 2011

What is Shortcut to Open Terminal in Linux Ubuntu?

I just got the shortcut to open terminal in Linux Ubuntu from my best friend. The shortcut is Ctrl+Alt+T. Haha... enjoy!

[Linux Ubuntu] How To Enable Arabic Keyboard Layout

I want to write Arabic in my Ubuntu box. So, I have to enable Arabic keyboard layout. Let's get started:

# Install language-pack-ar and language-pack-ar-base. These packages is used to translation for Arabic language
sudo apt-get install language-pack-ar language-pack-ar-base
# Install ttf-arabeyes for Arabic fonts and libfribidi0 for Arabic Unicode algorithm
sudo apt-get install ttf-arabeyes libfribidi0
# Don't forget language-support-ar package
sudo apt-get install language-support-ar
# Then go to System*Preferences*Keyboard. There are some tabs, choose Layout

# Click Add button and you will get a dialox box contains two tabs: By Country and By Language. Choose By Language then Arabic for Language and Arabic for Variants.

# Click Add button once more and you will see this icon in your main panel in desktop:
[Linux Ubuntu] How To Enable Arabic Keyboard Layout
# Click USA and it will be switched to Ara and vice versa.

I get this how-to here. Enjoy!

PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0

What should we do when get that message?
# Open /etc/php5/cli/conf.d/mcrypt.ini with your favourite editor like vi or gedit. You will see the content of mcrypt.ini
# configuration for php MCrypt module
# Replace sign '#' in the first line with ';'.
I get this message: "PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0" when trying to run PHP file via Terminal. Thanks for coming :).

How To Run PHP File in Terminal

Usually we use browser to execute PHP file. What about running your PHP file in Terminal? Let's follow these steps:

# Make sure you install these package:
  • php5
  • libapache2-mod-php5
  • php-pear
  • php5-mysql
  • php5-pgsql
  • php5-cli (those five are dependency of php5-cli)
sudo apt-get install php5 libapache2-mod-php5 php5-cli php-pear
php5-mysql php5-pgsql
# Make a PHP test file echoing "Running PHP file via Linux terminal ... " and save it as myfile.php

# Run PHP file:
php myfile.php
# You will get this message:
PHP Deprecated:  Comments starting with '#' are deprecated in
/etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0
# Open /etc/php5/cli/conf.d/mcrypt.ini with your favourite editor like vi or gedit. You will see the content of mcrypt.ini
# configuration for php MCrypt module
# Replace sign '#' in the first line with ';'.

Run myfile.php once again and ta-daa... You will see
Running PHP file via Linux terminal ...
in the Terminal. Enjoy!

Monday, April 4, 2011

[Linux Ubuntu] How to Monitor Network Utilization

Once more component should be monitored. It is network interface utilization. Here is the command line:
sar -n DEV 1
-n stands for network and DEV for DEVICE. This command will print network statistics for all available interfaces. In the next post we will try to daemonize these monitoring processes so that we don't need to issue the command manually.

[Linux Ubuntu] How to Check Disk and Swap Utilization

Disk and swap is a couple. When disk is full and he needs help, swap will ready to server :). How can we observe these two components of our server? Still employing sar, here is the code:
sar -d 1
sar -S 1
Parameter -d and -S for disk and swap, respectively. They will show us how many percent disk utilization or swap used. Enjoy!

[Linux Ubuntu] How to Check Memory Utilization

Yeah, we still employ the powerful sar (System Activity Reporter). This is a command line to check memory utilization by using sar:
sar -r 1
That's a per-second basis and you can add one more parameter to monitor the current second.
sar -r 1
The last "1" means sar only show one record only. Thanks for reading :)

[Linux Ubuntu] How to Check CPU Utilization

Make sure you follow the steps explained in previous post :). Using sar, we can also monitor CPU utilization per second. Just press Ctrl+Alt+T to open Terminal and here is the command line to check CPU utilization per second:
sar -u 1
If you want to know CPU utilization in current second, just add one parameter behind like this:
sar -u 1 1
And it's done!

[Linux Ubuntu] How to Check CPU/Processor Speed

Let's follow these steps:

# Make sure your pc connect to mirror and get updated (don't forget to set up source.list file)
sudo apt-get update
# Install sysstat package. This package contains complete-enough system performance tools for Linux
sudo apt-get install sysstat
# We will use one of package contained in sysstat. It is sar (System Activity Reporter). To check CPU or processor speed per second, issue this command in your lovely Terminal
sar -m 1
It is the mean speed of all of your processor cores. Enjoy!

[Linux Ubuntu] How to Set Repository in Terminal

Here is the content of source list file located in /etc/apt/source.list. I use this configuration for daily needs and it's enough (write it in one line only). You should edit source.list in root mode.
deb maverick main universe
restricted multiverse
Kambing is updated mirror and I can easily access this server. Change this address based on your location and nearest repository in your resident. Enjoy!