Archive for the ‘Linux’ Category

Static IP on OpenWrt

January 23, 2012 Leave a comment

If you want your router to assign a static IP on a specific OpenWrt Machice you just have to run something like the following:

uci set network.lan.proto=static
uci set network.lan.ipaddr=
uci set network.lan.netmask=
uci set network.lan.gateway=
uci set network.lan.dns=

/etc/init.d/network restart

Also you can edit accordingly the /etc/config/network file.

Categories: OpenWrt, Tutorials

Backup your Gmail account with getmail

December 29, 2011 1 comment

For almost a year now I am using Gmail as a client to access all my mail accounts. In this article I am going to describe how to make backups of you Gmail account with getmail. Getmail is a simple, yet powerful console tool that downloads your mails and of course it is written in Python. Also because it makes a backup of the mails in an mbox-formatted file, you can access them with many mail clients (like Thunderbird) that support this format.

After installing it (for Debian: “sudo apt-get install getmail4”) you just have to create a file named “~/.getmail/” that will contain the followings:

type = SimplePOP3SSLRetriever
server =
username =
password = yourpassword
type = Mboxrd
path = ~/gmail-archive/gmail-backup.mbox
verbose = 2
message_log = ~/.getmail/gmail.log

Here you can find some other examples on how to write the above configuration file.

Also you have to create the empty mbox file, “~/gmail-archive/gmail-backup.mbox”, that will contain your backed-up mails.

Then, go to the Gmail’s settings and select from the “Forwarding and POP/IMAP” tab, “Enable POP for all mail (even mail that’s already been downloaded)”. Also make sure to select for the “When messages are accessed with POP”, “keep Gmail’s copy in the inbox”.

Now you are ready to backup your Gmail account.
In order to do that, run the following command in the terminal:

getmail -r ~/.getmail/

You should see a long string of messages begin printing out as getmail starts grabbing the contents of your Gmail account.
Because Google has some limits on how many messages can be retrieved at one time you will have to run the command several times to retrieve all the mails.
Or just run something like the following:

# run the getmail command 1000 times
for i in `seq 1 1000`;
    getmail -r ~/.getmail/

It would be useful to auto-backup your mails periodically. Personally, I made a cronjob that checks for new mails hourly.
To do so, run:

crontab -e

And at the end of the document, add the following line:

@hourly /usr/bin/getmail -r path-to-your-home-folder/.getmail/

See also:
Why getmail and not fetchmail?
Gmail silently destroys mail

Credits to:

Categories: Linux

Static IP on Linux

August 7, 2011 Leave a comment

If you want your router to assign a static IP on a specific Linux Machice you just have to edit /etc/network/interfaces to look like below.

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
        address   # The static IP
Categories: Linux, Tutorials

How to install Debian – my way

August 1, 2010 12 comments

In this post I am not going to analyse the positive or negative (there is nothing negative :P) aspects of Debian.
I suppose that you know why Debian is such a good distro (number of packages, stability, rolling distro) and you want to install Debian but you are scared of the process. Actually it isn’t as difficult as it may sound. There is the easy way that you just install everything that the installation CD tells you or you can do something like the followings. My way of installing the Debian may be a little more ( 😯 ) complex but after understanding it, the whole process will be quite automated and quick.

Read more…

Categories: Debian, Linux Tags: ,

Java Problem in Debian: Network is unreachable

May 25, 2010 4 comments

Ok this is a very bad bug…
In the past, I was searching for a whole day to find out what was going wrong with a program (SUN SPOT Manager) that I wanted to run and now again for another two!
And all that, just because I had lost the link with the solution.

The problem turns up with java programs, running on Debian (squeeze), that have to access IPv4 addresses and the network, for some reasons, seems to be unreachable.

The “solution” is simple. You just have to run the following command:

sudo sed -i 's/net.ipv6.bindv6only\ =\ 1/net.ipv6.bindv6only\ =\ 0/' \
/etc/sysctl.d/bindv6only.conf && sudo invoke-rc.d procps restart

If you want to see more about this bug, have a look at this.

Also, if you are not bored, check this out… and you ‘ll understand the use of this kernel variable (net.ipv6.bindv6only), that creates the problem.

Categories: Debian, Java, Linux Tags: , ,

Pexpect module for Python 2.5

May 23, 2010 Leave a comment

Today I was searching for a way to run a bash command, that needed superuser’s permissions, from a python program that I had made… The problem was that I had to find a way to interact with the bash and when I would be asked for the password, the python program would answer with it.

So after some googling I found that awesome module called Pexpect , tested in Python 2.5, that allows to your python program to control and automate other programs.

As mentioned in its official site, Pexpect is basically a pattern matching system. It runs programs and watches output. When output matches a given pattern Pexpect can respond as if a human were typing responses. So it is very useful to automate some procedures, and others like testing and screen scraping. Also Pexpect is pure Python so it works on any platform that supports the standard Python pty module.

But enough with that!
Here is the code that I was talking about:

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <>.
# Author         : Aravanis Konstantinos
# Author's url   :
# Author's email :
# Tested in Python 2.5.5!

import pexpect
import getpass

class suError(Exception):
    """ A new exception. It is used from the su function, if there is a
    def __init__(self, value):
        self.value = value

    def __str__(self):
        return repr(self.value)

def su(command, password = None, prompt = "Enter SuperUser Password: ",\
        attempts = None):
    """ Function that ran a command with superuser's permissions.

        @command  : the command that must be ran with superuser's permissions
        @password : the superuser's password.
        @prompt   : the message that will be printed to inform that will ask
                    for the password, if it wasn't set.
        @attempts : the number of attempts. If it is not set then the program
                    will attempt for ever to gain the superuser's permissions.
                    If the attempts were set to zero, the program will still
                    run for a time.
    # decrease the number of the remaining attempts
    if attempts:
        attempts = attempts - 1

    # if the password hadn't been given then ask for it (from the
    # command line)
    if not password:
        password = getpass.getpass(prompt)

    # the command must be ran with superuser's permissions
    child = pexpect.spawn('su -c "' + command + '"')

    # when the password is asked, send it
    choice = child.expect(['Password:'])

    # check to see if there was an Authentication failure or else that
    # there was no problem
    choice = child.expect(['su: Authentication failure' ,pexpect.EOF])

    # if there was an Authentication failure, ask again for the password
    if choice == 0:
        # if the max number of attempts was reached
        if attempts < 1:
            raise suError("Too Many Attempts!")

        su(command, attempts = attempts)

    # return success
    return True

And if you want to test it:

# test it! #
    su("echo su_test_text > su_test_file", attempts = 3)
except suError:
    print "No other attempts left!"

Install LAMP (Linux Apache Mysql PHP) – phpmyadmin

May 30, 2009 1 comment

This mini-tutorial was written mainly for personal use. The following steps are an example of the installation with the use of apt-get package manager of Ubuntu and Debian. I think that the packages are the same with any other package manager.

  1. Update your repositories:
    • #apt-get update
  2. Install Apache and PHP:
    • #apt-get install apache2 php5 libapache2-mod-php5
  3. Install Mysql:
    • #apt-get install mysql-server mysql-client php5-mysql
  4. If you need to re-set the root password of the mysql server:
    • #mysql -u root
    • mysql> USE mysql;
    • mysql> UPDATE user SET Password=PASSWORD(‘new-password’) WHERE user=’root’;
    • mysql> FLUSH PRIVILEGES;
  5. Install phpmyadmin:
    • #apt-get install phpmyadmin
    • echo “Include /etc/phpmyadmin/apache.conf” >> /etc/apache2/apache2.conf

Now you are ready to start your webserver and build your sites etc etc

ps: Don’t forget the port forwarding: set all the ports to 80 and under TCP/UDP protocol.

Categories: Linux, Tutorials Tags: , , , , ,