sysadmin

Restore GRUB 2

In most of the systems GRUB is now upgraded to 2.0 and with this update the old restore process have also changed now there is no grub command :) available.

If you have lost the Bootloader after a routine reinstall or due to any other reason try the following to restore

Boot Using a Live CD and try the following as root

grub-setup -d /media/XXXXX/boot/grub -m /media/YYYYY/boot/grub/device.map /dev/sda

Where XXXXX represents the root partition and YYYYY represents the partition holding the /boot in case you dont have a seperate partition for /boot then XXXX and YYYY would be be the same. /dev/sda may change depending on the system you are using.

Please note this would erase the current bootloader and install a new one for you if you are unsure of what you are doing do not try this

Once done reboot and you will get the GRUB Menu in case you have lost your other OS from the Menu run a

grub-update

for more information visit the Documention here.

 

 

Using SQL * Plus on Command Line in Ubuntu

This blog post is an HowTo "Setup SQL*Plus to work on BASH" The commands illustrated in this howto are tested on Ubuntu 9.10 with Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production Installed.

What is SQL * Plus ?

SQL*Plus is a command line SQL and PL/SQL language interface and reporting tool that ships with the Oracle Database Client and Server software. It can be used interactively or driven from scripts. SQL*Plus is frequently used by DBAs and Developers to interact with the Oracle database.

Prerequisite

Oracle Database 10g Express Edition Release 10.2.0.1.0 Installed

Once you have Oracle 10g Installed successfully you can go to

Applications > Oracle Database 10g Express Edition > Run SQL Command Line

and successfully run all your SQL PL/SQL easily but using SQL*Plus directly on BASH is the real fun, Below are the steps which will enable you to use SQL*Plus on BASH

1) set ORACLE_HOME
2) set ORACLE_HOME/bin in $PATH

The above 2 steps can be performed by adding the following lines to .bashrc

export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/
export $PATH=$PATH:$ORACLE_HOME/bin

The above 2 Steps are sufficient to use SQL*Plus on Command Line once you have done the steps execute


$ sqlplus user/password@database

In the default install XE would be used as database.

Issues while using the default or only the above method

  • SQL*Plus does not support the Up/Down Arrow command scroll under linux environment which in itself is the biggest problem.
  • Default Editor is not Set which will confuse you while executing ED.
  • Various Other Environment variables are not set

Resolving the above mentioned issues

  • Install rlwrap this will enable the Up/Down Scroll function
    $ sudo apt-get install rlwrap
    now connect to oracle using
    $ rlwrap sqlplus user/password@database
    You will find that Up/Down Scroll is now enabled.
  • Set the most common Environment Variables


    $ rlwrap sqlplus user/password@database
    SQL*Plus: Release 10.2.0.1.0 - Production on Sun Feb 28 23:53:15 2010
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to:
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL> SET EDITFILE "afiedt.buf"
    SQL> DEFINE _EDITOR=vim
    SQL> SET LINESIZE 132
    SQL> SET SERVEROUTPUT ON

    This will set the default editor as VIM, Default Edit File as afiedt.buf LINESIZE as 132 & will mark SERVEROUTUT as ON
    various other variables can also be set similar commands on the SQL prompt

Refer SQL*Plus FAQ's for more information.

4 Steps to add Ubuntu Systems to Active Directory Setup

The IT environment today in any organization is a sort of a mixture where many different Operating Systems are used, and Windows Active Domain Controller exists in majority of such organization.

Below is a 4 step How to on "Connecting Linux (Ubuntu) Systems to Active Directory Setup"

1) Update the Software Repositories

sudo apt-get update

2) Install Required Packages (likewise-open)

sudo apt-get install likewise-open

3) Join The Domain using Domain Administrator Account, replace Administrator with Domain Administrator Username and fqdn..domain with the Fully Qualified Domain Name

sudo domainjoin-cli join fqdn.domain Administrator

4) Update the Startup Scripts

sudo update-rc.d likewise-open defaults
sudo /etc/init.d/likewise-open start

Thats it !! you have now joined the Domain, Log Off or preferably Restart the Machine.

Now you can login using Active Directory Credentials remember appending DOMAIN\ before your username


User Name to Login : DOMAIN\username
Password: domainpassword

This will also create a home Directory for Domain Users under /home/DOMAIN

Domains in Your own language

I am sure that by now you would have at least seen one domain name which was written in a non-english language but still if you have not seen any such domain the screen shot below would explain the entire story. I would try to explain the mechanism behind these kind of Domain Names in this post


Domain in Hindi

Domain Names which can be viewed in a language-specific script are known as Internationalized Domain Names or IDNs. This concept was introduced in December 1996 and was first implemented in 1998 but ICANN issued guidelines for the use of IDNA only in June 2003 any by today most of the TLDs support IDNs.

The Working

As we all know that a domain name has to resolve to an IP Address to function, but as language-specific domain names contains NON-ASCII characters and there are various limitations in their use, to overcome this basic limitation an encoding mechanism for such names is implemented by which this collection of  NON-ASCII characters are used to prepare a suitable character set which can be used, lets check the process with the following example


http://काशीपुर.com  = http://www.xn--11b6bsw3bni.com/

now अभिषेक.com contains 2 parts अभिषेक and com in which com is already an ASCII string and hence left as it is, अभिषेक is processed by Nameprep and then converted to Punycode to get l1b6a6dvbzbxc which is a meaningless string for most of us, this output is prepended with xn-- to produce xn--l1b6a6dvbzbxc which becomes the first part of the domain name an entry for this (xn--l1b6a6dvbzbxc.com) is made in DNS to map these names with IP Addresses.

IDNs are registered with a limited number of registrars by using their ASCII equivalent strings, currently .com/.net/.info and various other ccTLD are available for registration .org is expected to be available by this month (January 2010) end, ccTLD .in is currently not available for IDNs.

Starting November 2009 ICANN have started registering language-specific TLDs as well and such TLDs are expected to hit the internet somewhere mid-2010, we may soon see some domains with  .भारत as TLDs soon if Indian Government applies for such a TLD :)

IDNs are not much popular in India currently but still the domain parking race have already begun for Hindi TLDs for instance domains like भारत.com, पुणे.com and various others are already gone

Use of IDN have opened up new ways for Localization and Internationalization but using IDNs have also raised various ASCII Spoofing concerns due to which various Browsers do not have all the IDN TLDs enabled by default for instance  the Newer Versions Firefox  does not support .com IDNs by default to enable the same you need to set a parameter "network.IDN.whitelist.com;true" in firefox configuration using about:config, please be careful while doing so this may not be always recommended due to various reasons check this for further information on this.

Where .deb files are stored in Ubuntu ?

We always hear people saying ubuntu works well only when you have a strong internet connection as the Install CD doesn't contain all the packages required agreed now a CD cannot contain all the packages you require so you need to download the packages but there is a clear misunderstanding among new users that they always need to download these packages, Its essential to download them once but if you are reinstalling ubuntu on new machine you need not download these packages all over again if you have installed required packages on one of the machine you can use the content of below listed directory for installation

/var/cache/apt/archives

this directory contains the debian packages download by the apt-get :)

so have fun reuse the content for each install and save time and bandwidth

Search Engine Optimization using 301 Redirects

Search Engine Optimizations, i am very sure that all would have heard this term by now, in simple terms its a process of "making your website Search Engine friendly" there are various ways methods to do this, let me be very clear there is no specific way by which you can have a perfectly optimized website, in this post i discuss one of the methods by which you can remove the confusion of a search engine :).

Confused Search Engine !!! yes this happens often, just because of a silly mistake done unknowingly. Search engine often gets confused due to the links for example http://www.example.com and http://example.com may open same website but they are 2 different links and hence there are chances that both of them gets listed on search engines which is not what you will want to happen how to solve this problem ?

And i have a one line answer to this "by using 301 redirects" or "URL Redirections" below is the process by which you can implement this on various types of websites

For Websites hosted on Linux Servers

Edit .htaccess present in web root and add the following lines

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]

This will redirect requests for example.com to www.example.com ensure you have mod_rewrite enabled.

For Websites hosted on IIS use the following steps

  • In internet services manager, right click on the file or folder you wish to redirect
  • Select the radio titled "a redirection to a URL".
  • Enter the redirection page
  • Check "The exact url entered above" and the "A permanent redirection for this resource"
  • Click on 'Apply'

Just in case you don't have control on the server as if you are on a shared hosting which does not provide any such service you can also programatically  redirect below are the code for PHP and ASP similar kind of code is applicable for others

For PHP

<?php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.example.com" );
?>

For ASP

<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.example.com/"
%>

Hosting a Website from Local Machine

I am sure you would have thought atleast once of hosting your website from your machine itself, if not the website atleast a sandbox version of it as it would be comparatively easy for you to maintain it so i discuss the steps you need to follow to achieve this, first lets go through the requirements, in this post i am talking about small sized sites a minor modified version of this post is applicable for large sites as well.

Requirements

1) A really broad Internet Connection.
2) A Static IP
3) A High End Machine (if the site you are hosting is pretty static a lower end machine is sufficient to be more clear a dynamic personal blog kind of site will also never need more than 1000 Mb of RAM unless you are the Top blogger of the country)
4) Server Software (Apache preferred)
5) A Database Server (if needed, mysql/postgresql recommended)
6) Scripting Support (might be PHP. perl, python as per the requirements)

In simple words your local LAMP machine can work as the server for your website :)

I have the machine ready with a good internet connection and a static IP Now what

Hey you are almost done just a few entries here and there and you host the website from your home

Now you will need to resolve your domain to your IP address, now whats it and how will i do this

Its quite simple you need to add an entry in DNS so that it can resolve this, request your registrar to do this for you if you are unable to do this, generally you would be able to do this at no additional costs, in simple terms if you have registered a domain say example.com and your static IP is x.x.x.x then example.com should resolve to x.x.x.x thats it.

Once the above step is done and are planning to host only one website then your setup is ready :) if you need to host more than one domains on this single machine just add virtual hosts in your server configuration for each of the domains and make all domains pointing to same IP.

What else you will have to do ?

Keep this machine up 24x7 after all you will not like your site to be down

 

Also dedicate the machine as server dont try playing games on it, its a server now and putting extra load to it will slow down your site performance

I would warn hosting a server is not that easy as it looks like security issues can pop up now and then and you should be technically sound to handle this so its recommended spending some amount and  take a hosting plan from someone in the business after all he is there for providing you services.

Key Based Authorization with SSH

Using remote shells is all time favourite but remembering those many passwords is a pain so here are the steps to login using SSH without putting a password :)

 

1. Create a public ssh key, if you haven’t one already. Look at ~/.ssh. If you see a file named id_dsa.pub then you obviously already have a public key. If not, simply create one.

ssh-keygen -t dsa should do the trick. Please note that there are other types of keys, e.g. RSA instead of DSA.

2. Make sure your .ssh dir is not publically writable

    # chmod 700 ~/.ssh

3. Get your public ssh key on the server you want to login automatically.
   
    #scp ~/.ssh/id_dsa.pub remoteuser@example.com

4. Append the contents of your public key to the ~/.ssh/authorized_keys and remove it.

Important: This must be done on the server you just copied your public key to. Otherwise you wouldn’t have had to copy it on your server. Simply issue something like

 

    # cat id_dsa.pub >> .ssh/authorized_keys while at your home directory.

 

5. Instead of steps 3 and 4, you can issue something like this:
   
    # cat ~/.ssh/id_dsa.pub | ssh -l remoteuser remoteserver.com 'cat >> ~/.ssh/authorized_keys'

   6. Remove your public key from the home directory on the server.

   7. And you are in

    # ssh -l remoteuser example.com
        or
    # ssh remoteuser@example.com

 

 without getting asked for a password.