Wednesday, July 8, 2015

How to fix "nickname is already in use" error in irc?

What causes IRC to throw "nickname is already in use":
1.  You are not closed your previous session of IRC chat
     a) Trying to login with same nickname in another place/application with 
          existing active connection.
2.  You are internet connectivity disconnected & IRC server not released 
      your session.

How to fix:
a) /msg nickserv ghost <your_nickname> <password>
b) /msg nickserv <your_nickname>
b) /msg NickServ identify <password>

Tuesday, July 7, 2015

Migrate Postgresql 9.1 to 9.4 in 4 steps

Postgresql elephant
By Jeff MacDonald [BSD], via Wikimedia Commons


$pg_lsclusters - Shows the currently running (online/down) postgres DB

$sudo pg_ctlcluster 9.1 main stop - Stops the running postgres 9.1

$sudo pg_upgradecluster 9.1 main - Upgrades(migrates) postgres to newer version(upgrade time depends on the amount of data).

Check whether the upgrade went fine and the newer version of postgres works fine by
$su postgres
postgres@xyz:/$ psql
psql (9.4.3)                       Now postgresql upgraded to new version
Type "help" for help.
postgres=#\l                     -   Check all your databases are available or not
postgres=#\c <your_database_name>  - Connects to your database
postgres=#select * from <your_table_name> - Check the content is same.

Optional:
$sudo pg_dropcluster 9.1 main  -  Do this only, If you really want to drop your old postgres cluster.

Monday, June 29, 2015

How to dist-upgrade BOSS GNU/Linux?

I am user of BOSS GNU/Linux version 5.0(code name: anokha) since a few years and i am content with it.  It's been about a year that the next version 6.0 (code name: anoop) is out there for public usage, I am bit afraid to upgrade my machine.  There are two reasons for my hesitation,

1.  I am completely adapted(/addicted) to BOSS 5.0, and pretty much comfortable with it.  I don't want to lose my comfortableness.

2.  I afraid to dist-upgrade, which many a time leads to -> at minimum inconsistency & at maximum machine crash.

So, what made me to upgrade my linux box?
It's been about 2 years since my last bug-fix to LibreOffice office suite.  And that FOSS contribution itch starts now again.  So, I decide to download & compile the source code LibreOffice in my Linux box.  But, Unfortunately when I to do so I end up with the error

"libo/sal/qa/rtl/strings/test_oustring_stringliterals.cxx: In member function ‘void test::oustring::StringLiterals::checkOUStringLiteral1()"
libo/sal/qa/rtl/strings/test_oustring_stringliterals.cxx:195:48: internal compiler error: Segmentation fault

As the reason pointed out by the LibreOffice developers, I have to use gcc-4.8 or higher version to compile the LibreOffice source.  But, It's not available with BOSS 5.0 (which derived from Debian release wheezy) and the same is with debian also (even backports also don't have gcc-4.8).  This leads to only one solution i.e upgrading the machine.
BOSS GNU/Linux Logo

Now, The steps to dist-upgrade your BOSS GNU/Linux machine.
(Note: 
* First backup all your (important)data, configuration files before proceeding the upgrade your machine.
* Ensure you have active internet connection throughout the following process.
* The process data consuming, it needs about 2.0 GB of data transfer) 

Steps to do in current version with the current repository (in our case BOSS 5.0 anokha)
1.  update the machine
     $sudo apt-get update 
2.  upgrade the machine
     $sudo apt-get upgrade
3.  dist-upgrade the machine
     $sudo apt-get dist-upgrade
     The steps 2 & 3 must be finished successfully without any errors.  If you end-up with errors first fix it, without you can't proceed.  And importantly
check each time what are the packages going to be removed.  If you find anything important shown as going to be removed, be ensure twice with double cautions is it ok to you and then proceed.

Steps to do in current version with the target repository (in our case BOSS 6.0 anoop)
1.  Modify the "/etc/apt/sources.list" to point to the new version's repository.  For our case open & edit the file "/etc/apt/sources.list" file as follows.

$sudo gedit /etc/apt/sources.list

existing:
deb http://packages.bosslinux.in/boss anokha main contrib non-free
deb-src http://packages.bosslinux.in/boss anokha main contrib non-free


After modification:
deb http://packages.bosslinux.in/boss anoop main contrib non-free
deb-src http://packages.bosslinux.in/boss anoop main contrib non-free


save and exit.

2. update the machine
   $sudo apt-get update

3. Upgrade the machine
   $sudo apt-get upgrade

4.  Upgrade the machine
   $sudo apt-get dist-upgrade

  In the 3 & 4 th steps be in & around your machine, as the new versions of the packages installed it will prompt for configuration file changes.  For example let's take "postgresql" configuration file.  You may be modified it for your previous needs.  As the newer version going to be installed you will be prompted with options to keep older configuration file, replace with new etc., give your option accordingly (default & recommended is keeping your old configuration file).  Once you crossed all the said steps successfully, machine will prompt for "reboot", after which you could be landed into newer version of BOSS GNU/Linux.

How to check the upgraded version?
$hostnamectl
output will be something like

    Static hostname: boss
              Icon name: computer-desktop
                  Chassis: desktop
            Machine ID: 62c6fd7923f0953d60
                  Boot ID: 5449ccd6794947cc8309fdff20546b0b
Operating System: BOSS GNU/Linux 6 (anoop)
                   Kernel: Linux 3.2.0-4-686-pae

Kernel Upgrade:
From the above output we are sure that the machine is i686 arch so we have to install the newer kernel of same architecture.  So, we will find the newer/latest linux kernel available in our repository and install.  First let us check the available linux kernels using
$apt-cache search linux-image  - outputs something like follows
linux-image-3.16.0-4-586 - Linux 3.16 for older PCs
linux-image-3.16.0-4-686-pae - Linux 3.16 for modern PCs
linux-image-3.16.0-4-686-pae-dbg - Debugging symbols for Linux  \ 3.16.0-4-686-pae
linux-image-3.16.0-4-amd64 - Linux 3.16 for 64-bit PCs
linux-image-486 - Linux for older PCs (dummy package)
linux-image-586 - Linux for older PCs (meta-package)
linux-image-686-pae - Linux for modern PCs (meta-package)
linux-image-686-pae-dbg - Debugging symbols for Linux 686-pae configuration (meta-package)
linux-image-amd64 - Linux for 64-bit PCs (meta-package)
linux-image-3.2.0-4-686-pae - Linux 3.2 for modern PCs
linux-headers-3.2.0-4-686-pae - Header files for Linux 3.2.0-4-686-pae

The existing kernle is linux-3.2 and we have linux-3.16 in our repository for i686 architecture.  So, we could proceed with installation of new kernel
$sudo apt-get install linux-image-3.16.0-4-686-pae

Now, your machine will prompt you for rebooting.  Before rebooting you may consider purging removed packages(optional but recommended).


Purging removed packages:
Purge = (In Linux) Complete removal of a package including configuration files.  Many a time a package removed but its configuration files may stay with the machine.  To remove those unnecessary configuration files we purging.

$ dpkg -l | awk '/^rc/ { print $2 }'  - Lists all the removed packages
$sudo apt-get purge $(dpkg -l | awk '/^rc/ { print $2 }') - purge the removed packages.


 

Monday, June 22, 2015

How to print the current line and the file name in a c program?

'C' compilers usually define preprocessor macros along with our header file inclusion macro.  There are many different useful preprocessor macros available, two of them are __FILE__ & __LINE__. 

__FILE__ -> will be replaced by the executing filename.

__LINE__ -> will be replaced by the current line of execution.

Example program - test.c:

1 #include

3 int main()
4 {
5  printf("\n%s\t%d",__FILE__, __LINE__);
6  return 0;
7 }

while running the above program outputs:
tst.c        5


Thursday, May 7, 2015

How to block websites and show warning page in local machine using webserver?

This post specific to Debian based linux

3 main steps:
1. Add website entries in the /etc/hosts file
2. Setup a webserver in local machine
3. Create files to serve using web server.

1. Add website entries in /etc/hosts file

    Open /etc/hosts file in an editor (as a super user, for normal users the file will open only in readonly mode.).  The typical content of the file will looks like

#Local Machine
127.0.0.1    localhost
127.0.1.1   

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters


add your new entries (websites to be blocked) at the bottom of the file like

127.0.0.1    twitter.com
127.0.0.1    yahoo.com
127.0.0.1    facebook.com
...
...
save and exit.

2. Setup a webserver in local machine.


  Any webserver can be used for the very purpose which ranges apache, Thin, twiggy, yaws, wbox, webfs, mini-httpd, lighttpd etc.,   As we are going to serve only one static webpage, It would be better if we use a very minimal, low foot print server.

I found micro-httpd a optimum one for the purpose.  Now, do the following steps in terminal.

#touch /etc/inetd.conf

#sudo apt-get install micro-httpd inetutils-inetd

By default the service directory for the micro-httpd server is "/var/www".  But, if you want to change it, you can do so in the file "/etc/inetd.conf".

3. Create files to serve using web-server


Content of a sample warning page.

<html>
<head> <title> Warning page! </title> </head>
<body bgcolor="black">
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<div align="center" style="color: red; margin-top: 25%;">

<b><h2>
Very Sorry!The website you are trying to acces is blocked </h2>
</b> </div>
</body>
</html>

copy paste the above content in a file and save it with the name "index.html" under "/var/www/" directory.  Now, reboot your machine then try to access the blocked websites via browser.  Now, you can access all the websites for blocked one your browser will show the warning page.

Thursday, April 9, 2015

How to Open/Browse sqlite files in Linux?

What is sqlite?
As per "wikipedia"
    SQLite is a relational database management system contained in a C programming library. In contrast to other database management systems, SQLite is not a client–server database engine. Rather, it is embedded into the end program.
   
Where it is used?
    Browsers,
    Mobile Operating systems
    Mobile Apps,
    Web Frame Works like Django, Ruby on Rails etc.,
   
In (Debian based)Linux (am Using BOSS GNU/Linux) there are many GUI/CUI applications available to work with sqlite. Few of them are
CUI:
    sqlite
    sqlite3
   
GUI:
    sqlitebrowser (Now renamed as  "SQLite Database Browser" or simply DB browser)
    sqliteman (Download from here http://sqliteman.yarpen.cz/)
    sqlitestudio (Download from here http://sqlitestudio.pl/)