Monday, March 7, 2011

Comic strip in Kubuntu

This was a fun experiment. I read the dilbert comics using the comic strip widget in Kubuntu. The comics started from 01-01-1994 on the widget while on the website, the first one was on 16-04-1989. Well, I cannot just sit back and miss on the 5 years of comics now, can I??

To change the start date, you will need to modify the start date in ~/.kde/share/apps/plasma/comics/dilbert/contents/code/main.es file.

Open the file in any text editor and search for 1994. The line should be something like -
comic.firstIdentifier = "1994-01-01"
just change it to
comic.firstIdentifier = "1989-04-16"
to get the comics from 1989 onwards. Once you make the change, right click on the widget and click on the "Jump to first strip" option to get the first strip from 1989. Enjoy.

Sunday, February 6, 2011

Setting up periodic mysql backup

I had to setup periodic mysql backups on a ubuntu server recently. Posting the steps here as a guide.

The basic command to take a mysql dump is simple -
mysqldump -u -p > filename.sql

For e.g., if you have your password for root user of mysql is rootpassword and the database that you want to backup is sampledb, you would use -
mysqldump -uroot -prootpassword sampledb > filename.sql

My problem was a little different since I wanted to take the backups by date. I used something like -
mysqldump -uroot -prootpassword sampledb > db_dump_`date '+%d_%m_%y'`.sql

I simply added a date '+%d_%m_%y' in the file name. This command displays the date in dd_mm_yyyy format.

Next step was to deciding how many days worth backup to keep. I decided to keep backups for last 31 days in my case. This would mean that the older backups would be removed if their age exceeds 31 days.

Note that next step we are going to remove files older than 31 days. This being a destructive command, you should take care to run in inside a folder where you know the files are only backups. In my case, I save all my database backups into a separate folder and run this command there.

In unix, you can search all files older than a given age by using the find command. For e.g.
find ~/dumps/ -type f -mtime +31
This command will find all the files under dumps folder in home which were modified more than 31 days ago. I am assuming here that your are not changing anything manually in the file after they have been created by mysqldump.

The above command just did the list but we need a way to delete the found files. There is another option for find that can help us here.
find ~/dumps/ -type f -mtime +31 -exec rm {} \;
The above command will find and delete all files from the dumps folder under your home which are older than 31 days. The exec option tells find to execute the next command (rm in this case) on the searches.

The next step was to create a script so that I need to use only one command to take the backup and remove the older files. If you are in (k)ubuntu, you can create a bin folder under your home and put all your scripts there. This will put the script in the default path for your commands.

Then you can create a backup.sh file and put the commands in it. Make sure to give execute permissions for the backup.sh file.

The final step is to create a cron job to automate the whole process. For this enter crontab -e on the command line. It should open up an editor to enter your cron settings.

I used the following in my crontab
1 0 * * * ~/bin/backup.sh
This tells the cron to run the backup script every night at 12:01 AM.

Sunday, March 21, 2010

Configuring samba server on Ubuntu (from command line)

This is a basic tutorial which aims to configure samba on an Ubuntu (debian) machine and create a network user for it. Later when I am not as lazy, I will probably elaborate on this, but for the moment this will atleast get you started.


Run the following commands to install and configure samba server. Each command is preceded by the description for it.

Install samba server and dependencies

sudo apt-get install samba

add a default group for accessing samba
sudo groupadd samba-group

create an user for accessing samba and add it to the group created earlier (this will prompt for a password which will be your samba password)
sudo useradd --gid samba-user --shell /bin/false samba-group --home /nonexistent

add the user to the samba password file
sudo smbpasswd -a samba-user

change to your home (cd also works)
cd $HOME

create the share folder
mkdir shared-folder

change the ownership for the share folder and give apt permissions
sudo chown YourUserNameHere:samba-group shared-folder

sudo chmod 775 shared-folder
sudo chmod g+s shared-folder

edit the samba configuration file (i just happen to like vim, but you can use any editor)
sudo vim /etc/samba/smb.conf

in this file

  • Delete the ; in front of security = user, i.e. change to -

security = user,

  • Add the following to the end of the "Share Definitions" section.
    (You will need to change: path = /home/YourUserNameHere/shared-folder).

[sharer]

path = /home/YourUserNameHere/shared-folder

valid users = samba-user

read only = No

create mask = 0777

directory mask = 0777


Now we are done. You should be able to access the samba share from windows system by giving the IP/shared-folder (for e.g. type \\192.168.0.120\shared-folder in start->run). Use the username/password as samba-user/.

Saturday, March 20, 2010

Install PHP-Oracle bridge in Linux

Note: These instructions are for 32-bit ubuntu 9.0.4 machine. Make sure you download the appropriate packages according to system.

Install the instantclient and configure it

Download the Basic and the SDK packages for oracle from:

Now run the following commands on the shell. Descriptions for each command precede them:


Create a folder to unzip the files

# mkdir -p /opt/oracle/instantclient


Go to the created folder

# cd /opt/oracle/instantclient


Unzip the basic and sdk zip files

# unzip instantclient-basic-linux32-10.2.0.1-20050713.zip

# unzip instantclient-sdk-linux32-10.2.0.1-20050713.zip

Add instant-client information to ldconfig

# echo /opt/oracle/instantclient/instantclient_10_2 >> /etc/ld.so.conf

# ldconfig


Go to the unzipped instantclient folder

# cd /opt/oracle/instantclient/instantclient_10_2


Manually create symlinks named libclntsh.so and libocci.so as mentioned below.

# ln -s libclntsh.so.10.1 libclntsh.so

# ln -s libocci.so.10.1 libocci.so


Download the oci8 module with pear.

Pear is in the php5-pear package. You need php5-dec package for phpize

# sudo apt-get install php5-pear php5-dev

Create a folder to install oci8

# mkdir -p /usr/local/src

Change to the created folder

# cd /usr/local/src

Download the oci8 module

# wget http://pecl.php.net/get/oci8-1.3.5.tgz


Extract the tar contents

# tar xzvf oci8-1.3.5.tgz

Change to the extracted folder

# cd oci8-1.3.5

Run phpize

# phpize

Configure oci8 with instantclient, make and make install

# ./configure --with-oci8=shared,instantclient,/opt/oracle/instantclient/instantclient_10_2/

# make

# make install


To enable the oci8 module for php, edit /etc/php5/apache2/php.ini

and put this line after the examples starting with ;extension

[OCI8]

extension=oci8.so

Restart Apache.

# sudo service apache2 restart

You should be able to see the oci8 module in the output of phpinfo().