Skip to content

Posts tagged ‘Ubuntu’

12
May

Backup Subversion Repositories And Projects

After I decided to manage my PhD thesis and projects with subversion, the most important thing to consider was a proper backup strategy. I decided to go a bit overboard with it as it might save me some day. There are several ways to backup subversion and I decided to use all of them!

a. Using crontab and rsync to backup subversion

Read my earlier post on crontab if you are not familiar with it. Someday I will write about rsync as well. But for now read this if you are new to rsync. I use the following code to backup the entire subversion repository to my backup directory.

rsync -av --delete --progress /source_directory/subversion/ /destination_directory/backups/subversion_backup/

I used crontab to schedule the above job to run at midnight every day. In case something happens to the original subeversion repository, it is easy to retrieve data from this backup – just copy it to the original location!

b. Using the backup script from COLLABNET (the subversion guys)

The next technique it to use the python based backup script from subversion called hot-backup.py. This script can be used to make a backup of the latest version of the subversion repository. I used the following code to download the latest version from COLLABNET website and install it on my system.

wget http://svn.collab.net/repos/svn/trunk/tools/backup/hot-backup.py.in
mv hot-backup.py.in hot-backup.py

Once that is done, I had to make some configuration changes in the file. The following lines were changed

# Path to svnlook utility
svnlook = r"@SVN_BINDIR@/svnlook"
# Path to svnadmin utility
svnadmin = r"@SVN_BINDIR@/svnadmin"

to look like this

# Path to svnlook utility
svnlook = r"/usr/bin/svnlook"
# Path to svnadmin utility
svnadmin = r"/usr/bin/svnadmin"

The next step is to run the script check if everything is fine. I used the code below:

python hot-backup.py --archive-type=zip --num-backups=10 ~/source_directory/subversion_repository /destination_directory/subversion_backup/

The above code will make a hotcopy of the latest version of the subversion repository into the backup directory in zip format. A total of 10 backups will be maintained at a time, oldest one being deleted when new ones are added.

Once the backup was properly inspected I created a cron job to run this command at midnight every day.

c. Using the subversion ‘hotcopy’ command

This is a very simple technique as it uses the inbuilt ‘hotcopy’ command to backup the svn repository. Follow the command below to make a reliable incremental backup of your svn repositories.

svnadmin hotcopy /source_directory/subversion_repository /destination_directory/subversion_backup/

Create a cron job to schedule it.

Once you have your backup system in place, rest assured that your data are safe.

11
May

Inspecting Network Cards In Ubuntu

I was planning to upgrade my home network into Gigabit. Before I start to spend money on it, I wanted to check the capabilities of the network cards on my laptop. Here is how I did it.

Install ‘hwinfo’. Its quite an useful tool as it can check the configuration of any hardware. Refer the manpage of more information.

sudo apt-get install hwinfo

To display details of the network cards on the system, type:

sudo hwinfo --netcard

Alternatively one can use

lshw -C network

to display details of the network card. Read manpage for more on lshw.

8
May

Scheduling Commands With Crontab In Ubuntu

The following applies to any linux distribution

Crontab

Crontab is an integral part of most Linux distributions.It is a simple text file that holds a list of commands that are scheduled to be run at specified times. These commands, and their relative run times, are controlled by the ‘cron’ daemon and are executed in the system background.

Each user on a Linux system has their own crontab which contains the schedule of commands. In order to edit or create a crontab, one must use the text editor that is specified by the system, ‘nano’ being the default on my system. To create a crontab open a terminal and type:

crontab -e

‘nano’ will open with a blank window for the job schedule to be entered. Each line represents a seperate cron job entry – also known as a ‘cron job’.

Creating a ‘cronjob’

Each section in a cronjob is separated by a space, with the final section having one or more spaces in it. No spaces are allowed within sections 1-5, only between them. Sections 1-5 are used to indicate when and how often the task has to be executed. This is how a cron job is layed out:

minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday), command

Example 1

01 04 1 1 1 /usr/bin/somedirectory/somecommand

The above example will run /usr/bin/somedirectory/somecommand at 4:01am on any Monday which falls on January 1st. An asterisk (*) can be used so that every instance (every hour, every weekday, every month, etc.) of a time period is used. Code:

Example 2

01 04 * * * /usr/bin/somedirectory/somecommand

The above example will run /usr/bin/somedirectory/somecommand at 4:01am on every day of every month.

The “/usr/bin/somedirectory/somecommand” text in the above examples indicate the task that will be run at the specified time. It is recommended to use the full path to the desired command as shown in the above examples. Crontab will echo any mistakes found in a cronjob. The crontab will start running as soon as it is properly edited and saved.

Other crontab options

crontab -l option causes the current crontab to be displayed on standard output.
crontab -r option causes the current crontab to be removed.
crontab -e option is used to edit the current crontab using the editor specified by the EDITOR environment variables
($EDITOR=vi crontab -e).

Note: The double-ampersand (&&) can also be used in the “command” section to run multiple commands consecutively.

7
May

Monitoring Real-time User Logins In Ubuntu 8.04 Server

‘whowatch’ is a console, interactive users and process monitoring tool. It displays information about the users currently logged on to the machine, in real-time. Besides the standard informations such as login name, tty, host and the user’s processes, the type of the connection (ie. telnet or ssh) is also shown. A particular user can be selected and his processes tree may be viewed. Trees are displayed with an additional column that shows the owner of each process. In the process tree mode SIGINT and SIGKILL signals can be sent to the selected process. Killing processes is just as simple and fun as deleting lines on the screen [information from somewhere on the www]. To install ‘whowatch’:

sudo apt-get install whowatch

28
Apr

Free TeX and LaTeX Ebooks

TEX is a typesetting program, originally written by Prof. Knuth at Stanford around 1978. It implements a macro-driven typesetters’ programming language of some 300 basic operations and it has formed the core of many other desktop publishing (DTP) systems. Although it is still possible to write in the raw TEX language, you need to study it in depth, and you need to be able to write macros (subprograms) to perform even the simplest of repetitive tasks [Peter Flynn, 2005].

LaTeX is a user interface for TeX, designed by Leslie Lamaport at Digital Equipment Corporation (DEC) in 1985 to automate all the common tasks of document preparation. It provides a simple way for authors and typesetters to use the power of TEX without having to learn the underlying language. LaTeX is bundled with Metafonts, typesetting utilities and document formats. In Linux, TeX is distributed as teTeX and in windows TeX is distributed as MiKTeX. Another distribution of TeX is PDFTeX and it produces outputs in adobe acrobat format. They are many TeX IDEs around, my favorites being Kile, Kate and Kwrite.

Following are some free TeX and LaTeX ebook download links. Learn LaTeX to make it work for you!

a. Making TeX Work View/Download
b. TeX by Topic View/Download
c. The Not So Short Introduction to LaTeX 2nd Edition View/Download
d. A Beginner’s Introduction to Typesetting with LaTeX View/Download
e. A Gentle Introduction to TeX View/Download
f. Math Into LaTeX : an introduction to LaTeX and AMS LaTeX View/Download
g. The teTeX HOWTO: The Linux-teTeX Local Guide View/Download
h. A Simplified Introduction to LaTeX View/Download
i. Document Publishing View/Download
j. Getting Started With LaTeXView/Download
k. TeX For The Impatient View/Download

22
Apr

How To Check The Memory Usage Stats On Ubuntu Server Via Command Line

Following are some methods to check the memory usage in Ubuntu. More details about these tools can be found from the man pages.

free

free command displays amount of total, free and used RAM in the system, as well as shoing information on shared memory, buffers, cached memory and swap space used by the Linux kernel.

vmstat

vmstat reports report virtual memory statistics, which has information about processes, swap, free, buffer and cache memory, paging space, disk IO activity, traps, interrupts, context switches and CPU activity. With vmstat command, administrators can has instantaneous reports on memory usage.

top

top command displays dynamic real-time view of the running tasks managed by kernel and system information in Linux system. The memory usage stats by top command include real-time live total, used and free physical memory and swap memory with their buffers and cached memory size respectively.

ps

ps command reports a snapshot on information of the current active processes. Advantage of ps command is that system admins will be able to see where the memory is used. ps will show the percentage of memory resource that is used by each process or task running in the system. With this command, top memory hogging processes can be identified.

22
Apr

Turn Off Your Monitor Via Commad Line In Ubuntu

Save Energy and Your Bills!

If you forgot to turn off your monitor at home, SSH into the machine and type:

$ xset dpms force off

This will turn off your monitor. It will turn back on after a keypress or when you move the mouse. Alternatively, if you want to turn on a remote monitor use

$ xset dpms force on

You can check the status of the X Server setting by typing

$ xset -q

15
Mar

Migrating MediaWiki To A New Server

Today I decided to move my MediaWiki (MW) from the ailing old server to the new one. Overall it was a fairly simple process but I wanted to share a few things that I learned from the experience.

1. The database

a. Creating the backup

The very first thing that I had to do was to create a safe backup of my MW database. This database now contains all the data in my MW including images, user settings, comments and chats. To do this in MySQL I used the following syntax:

mysqldump -u username -p databasename > database.sql

b. Creating a new database
This created a file containing all the data from the old database. I used a copy of this file to create a new database in my new server. To do this  I had to first create the database and then import the data using the following syntax:

mysql -u root -p new_database_name < database.sql

c. Creating a database user

Then I created an account that has access to this database and gave it permissions.  Details about this new user can be found in the LocalSettings.php file of the MW.  Details about the database connection can also be found in this file. For example:

$wgDBserver         = “localhost”;
$wgDBname           = “database_name”;
$wgDBuser           = “username”;
$wgDBpassword       = “password”;
$wgDBtype           = “mysql”;

I used the following commands to give proper permission to the new MySQL user account.

GRANT DELETE,INSERT,SELECT,UPDATE ON new_database_name.* TO ‘username’@localhost IDENTIFIED BY ‘password’;
GRANT DELETE,INSERT,SELECT,UPDATE ON new_database_name.* TO ‘username’@unnionline.com IDENTIFIED BY ‘password’;

2. Moving MW files

Now that the database is properly setup, the next step was to move the MW from the old server to the new one. I recommend anybody using this technique to stick with the original directory structure. I used ssh to do the transferring.

3. Configuring apache

Now that my MW is ready to go online, I had edit my apache configuration file to recognize and host the wiki. Details about configuring apache can be found at http://www.apache.org/

5
Dec

Basic Gnuplot Tutorial – I

This tutorial uses Ubuntu Heron, Python 2.5, python-gnuplot 1.8-1

from Numeric import *
import Gnuplot


g = Gnuplot.Gnuplot()

# generate x, y data to plot
x = arange(10, typecode=Float)
y = x**2

# convert to a form that the gnuplot interface can deal with
d = Gnuplot.Data(x, y, title='data from python')

g.xlabel('x')
g.ylabel('x^2') # looks nice in the postscript

g.plot(d) # actually plot the data

# To Save as postscript. The enhanced=1 is to handle the x^2 in the xlabel.
# Use eps=1 to produce encapsulated postscript.
g.hardcopy('gp_test.ps', enhanced=1, color=1)
raw_input('Saved as gp_test.ps ; please press return to continue...\n')

28
Nov

Configuring ActiveSync between Windows Mobile 6.0 and Ubuntu on Sony Vaio

This article will take you through setting up an ActiveSync connection between Windows Mobile 6.0 on T-Mobile MDA II (called WM from hereon) and Ubuntu Heron running on Sony Vaio FZ31S/Z.

When connected via USB, Ubuntu Heron on Sony VAIO laptops does not recognise WM. So our first task is to make Ubuntu see WM. This can be accomplished by installing usb-rndis-lite driver as shown

svn co https://synce.svn.sourceforge.net/svnroot/synce/trunk/usb-rndis-lite
cd usb-rndis-lite/
make
sudo ./clean.sh
sudo make install

Now, run dmesg | grep rndis to see if `rndis’ is actually recognising to your mobile device

The next task is to install software that can communicate with the WM. Do this by adding the following lines to /etc/apt/sources.list and running sudo apt-get update afterwards.

deb http://ppa.launchpad.net/synce/ubuntu hardy main
deb-src http://ppa.launchpad.net/synce/ubuntu hardy main

Once we have done that, the next step is to install software that can actually sync our mobile with Ubuntu. `Synce’ and `odccm’ are the two sync engines and `synce-kpm’ is the user interface tool that we are going to use here. To Install all this follow the step below

sudo apt-get install synce-sync-engine librra0-tools librapi2-tools odccm synce-kpm

Having done all that, you can now check the ActiveSync connection by running synce-kpm and creating a partnership between your WM and Ubuntu Vaio. If nothing seems to work try..

a. reconnecting your mobile

b. soft resetting your mobile

c. restarting your laptop and then connecting your mobile.