Wednesday, January 25, 2012

Top 5 Best Databases


MySQL
If you are new to any of the top 5 database mentioned here, please read the rest of the article to understand more about them.

1. MySQL

MySQL is used in almost all the open source web projects that require a database in the back-end. MySQL is part of the powerful LAMP stack along with Linux, Apache and PHP.
This was originally created by a company called MySQL AB, which was acquired by Sun Microsystems, which was acquired by Oracle. Since we don’t what Oracle will do with MySQL database, open source community has created several forks of MySQL including Drizzle and MariaDB.

Following are few key features:
  • Written in C and C++.
  • MyISAM storage uses b-tree disk tables with index compression for high performance.
  • Support for partitioning and replication.
  • Support for Xpath, full text search.
  • Support for stored procedures, triggers, views etc.,
Additional Information:

2. PostgreSQL

PotgreSQL is a open source object-relational database system. It runs on most *nix flavours, Windows and Mac OS. This has full support for joins, views, triggers, stored procedures etc.,
Following are few key features:
  • MVCC – Multi-Version Concurrency Control
  • Hot backups and point-in-time recovery
  • Support for tablespaces
  • Asynchronous replication
  • Highly scalable
Additional Information:

3. Oracle

Oracle is the best database for any mission critical commercial application. Oracle has following four different editions of the database: 1) Enterprise Edition 2) Standard Edition 3) Standard Edition One 4) Express Edition
Following are few key features of the oracle database.
  • Real Application Cluster (RAC)
  • Data Guard for standby database
  • Virtual Private Database
  • Automatic Memory, Storage and Undo Management
  • OLAP, Partitioning, Data Mining
  • Advance Queuing, XML DB, Support for Spatial data
  • Flashback Database, Query, Table and Transaction
Additional Information:

4. SQLite

SQLite does not work like a traditional client-server model with standalone process. Instead, it is a self-contained, server-less SQL database engine.
Main Features of SQLite:
  • Zero configuration with no setup or admin tasks.
  • Complete database is stored in a single disk file.
  • No external dependencies
  • Supports database of several TB in size
  • Work on most *nix flavors, Mac OS X, windows. It’s also cross-platform.
  • WinCE is supported out-of-the box
Additional Information:

5. Microsoft SQL Server

This is Microsoft’s flagship Database product. If you are stuck in a company that heavily uses Microsoft products, you might end-up working on MS SQL Server.

How to Debug C Program using gdb in 6 Simple Steps

Write a sample C program with errors for debugging purpose
To learn C program debugging, let us create the following C program that calculates and prints the factorial of a number. However this C program contains some errors in it for our debugging purpose.
$ vim factorial.c
# include 

int main()
{
	int i, num, j;
	printf ("Enter the number: ");
	scanf ("%d", &num );

	for (i=1; i
$ cc factorial.c

$ ./a.out
Enter the number: 3
The factorial of 3 is 12548672
Let us debug it while reviewing the most useful commands in gdb.

Step 1. Compile the C program with debugging option -g

Compile your C program with -g option. This allows the compiler to collect the debugging information.
$ cc -g factorial.c
Note: The above command creates a.out file which will be used for debugging as shown below.

Step 2. Launch gdb

Launch the C debugger (gdb) as shown below.
$ gdb a.out

Step 3. Set up a break point inside C program

Syntax:

break line_number
Other formats:
  • break [file_name]:line_number
  • break [file_name]:func_name
Places break point in the C program, where you suspect errors. While executing the program, the debugger will stop at the break point, and gives you the prompt to debug.
So before starting up the program, let us place the following break point in our program.
break 10
Breakpoint 1 at 0x804846f: file factorial.c, line 10.

Step 4. Execute the C program in gdb debugger

run [args]
You can start running the program using the run command in the gdb debugger. You can also give command line arguments to the program via run args. The example program we used here does not requires any command line arguments so let us give run, and start the program execution.
run
Starting program: /home/sathiyamoorthy/Debugging/c/a.out
Once you executed the C program, it would execute until the first break point, and give you the prompt for debugging.
Breakpoint 1, main () at factorial.c:10
10			j=j*i;
You can use various gdb commands to debug the C program as explained in the sections below.

Step 5. Printing the variable values inside gdb debugger

Syntax: print {variable}

Examples:
print i
print j
print num
(gdb) p i
$1 = 1
(gdb) p j
$2 = 3042592
(gdb) p num
$3 = 3
(gdb)
As you see above, in the factorial.c, we have not initialized the variable j. So, it gets garbage value resulting in a big numbers as factorial values.
Fix this issue by initializing variable j with 1, compile the C program and execute it again.
Even after this fix there seems to be some problem in the factorial.c program, as it still gives wrong factorial value.
So, place the break point in 10th line, and continue as explained in the next section.

Step 6. Continue, stepping over and in – gdb commands

There are three kind of gdb operations you can choose when the program stops at a break point. They are continuing until the next break point, stepping in, or stepping over the next program lines.
  • c or continue: Debugger will continue executing until the next break point.
  • n or next: Debugger will execute the next line as single instruction.
  • s or step: Same as next, but does not treats function as a single instruction, instead goes into the function and executes it line by line.
By continuing or stepping through you could have found that the issue is because we have not used the <= in the ‘for loop’ condition checking. So changing that from < to <= will solve the issue.

gdb command shortcuts

Use following shortcuts for most of the frequent gdb operations.
  • l – list
  • p – print
  • c – continue
  • s – step
  • ENTER: pressing enter key would execute the previously executed command again.

Miscellaneous gdb commands

  • l command: Use gdb command l or list to print the source code in the debug mode. Use l line-number to view a specific line number (or) l function to view a specific function.
  • bt: backtrack – Print backtrace of all stack frames, or innermost COUNT frames.
  • help – View help for a particular gdb topic — help TOPICNAME.
  • quit – Exit from the gdb debugger.

How to Find and Delete Empty Directories and Files in Unix


Find empty directories in the current directory using find -empty

find . -type d -empty
Use the following command to remove all empty directories under the current directory.
find . -type d -empty -exec rmdir {} \;
Note: It is not recommended to remove empty directories from /etc/ or any other system directories.

Find empty files in the current directory using find -empty

find . -type f -empty
Note: Typically empty files are created by some programs as place holders, or as lock files, or as socket files for communication.

How many empty files are located under the current directory (and sub-directories)?

To count the number of empty files under current directory, pipe the find command to wc -l
find . -type f -empty | wc -l

How many non-empty files are located under the current directory (and sub-directories)?

find . -type f -not -empty | wc -l
Note: Find option -not reverts the option that follows it.
In all the above examples, replace the ( . ) dot with any other directory-path under which you would like to search the files.

How to Convert Text Document to Speech on Ubuntu Using eSpeak


Ubuntu espeak is a speech synthesizer for English (and several other languages) which will convert text to speech.
You can straight away execute espeak command on your Ubuntu machine without any installation or configuration.
In this article, let us review 8 examples of espeak command.

espeak Example 1: Speak the words specified in command line

This is the default usage.
# espeak --stdout 'words to speak' | aplay
Note: The above may also display the following message: “Playing WAVE ‘stdin’ : Signed 16 bit Little Endian, Rate 22050 Hz, Mono”

espeak Example 2: Speak the words specified in stdin

This will take the words interactively from the standard input and convert it to speech.
# espeak --stdout | aplay

espeak Example 3: Speak your document

This will convert the text from the mydocument.txt to speech.
# espeak --stdout -t mydocument.txt | aplay

espeak Example 4: Generate voice file from text document

Convert your text file to an audio file as shown below.
# espeak -t mydocument.txt -w myaudio.wav

Customizing espeak

If you find the default speech synthesizing is not good, you can try to customize it as explained below.

espeak Example 5: List all available voice languages

# espeak --voices
Pty Language Age/Gender VoiceName       File        Other Langs
 5  af             M  afrikaans         af
 5  bs             M  bosnian           bs
 5  ca             M  catalan           ca
 5  cs             M  czech             cs
 5  cy             M  welsh-test        cy
 5  de             M  german            de
 5  el             M  greek             el
 5  en             M  default           default
 5  en-sc          M  en-scottish       en/en-sc    (en 4)
.......

espeak Example 6: Choose a different voice language

The following will use “en-uk” – British english to translate the text to speech.
# espeak -v en-uk --stdout 'reading tips & tricks in TGS' | aplay

espeak Example 7: Increase or Decrease the number of spoken words per minute.

The default is 160 words per minute. You can reduce it using option -s as shown below.
# espeak -s 140 -f mydocument.txt | aplay

espeak Example 8: List the available espeak voices in specific language

The following example will display all possible english language variation that you can use for your text to speech conversion.
# espeak --voice=en
Pty Language Age/Gender VoiceName       File        Other Langs
 2  en-uk          M  english           en/en       (en 2)
 3  en-uk          M  english-mb-en1    mb/mb-en1   (en 2)
 2  en-us          M  english-us        en/en-us    (en-r 5)(en 3)
 5  en-sc          M  en-scottish       en/en-sc    (en 4)
 5  en             M  default           default
.....

Tuesday, January 24, 2012

Top 5 Best Linux Firewalls


iptables
If you are new to any of the top 5 firewalls mentioned here, please read the rest of the article to understand more about them.

1. Iptables

iptables is a user space application program that does packet filtering, network address translation (NAT), and port address translation (PAT).  iptables is for IPv4.  ip6tables is for IPv6.
iptables needs kernel with ip_tables packet filter (including Linux kernel 2.4.x and 2.6.x). Using iptables you can view, add, remove or modify the rules in the packet filter ruleset.

2. IPCop

IPCop is for small-office and home-office users. This is a Linux firewall distribution, that requires a separate low power PC to run the software. You can configure the firewall rules from a friendly web interface. This is a stateful firewall based on Linux netfilter.
You can take an old PC and convert it to a secure internet application with IPCop, which will secure the home/small-office network from internet and also improve web browser performance by keeping some frequently used information.

3. Shorewall

Shorewall firewall’s tag-line is: iptables made easy. It is also known as “Shoreline Firewall”. It is built upon the iptables/ipchains netfilter system.
If you have hard-time understanding the iptables rules, you should try shorewall, as this provides a high level abstraction of iptables rules using text files.
Shorewall contains the following packages:
  • Shorewall – Helps to create ipv4 firewall
  • Shorewall6 – Helps to create ipv6 firewall
  • Shorewall-lite – Helps to administer multiple ipv4 firewalls
  • Shorewall6-lite. Helps to administer multiple ipv6 firewalls
Additional information about shorewall:

4. UFW – Uncomplicated Firewall

UFW is a command line program that helps manage the netfilter iptables firewall. This provides few simple commands to manage iptables. Gufw is a graphical interface for the UFW that is used on Ubuntu distribution. It is very intuitive and easy to manage your iptables firewall using Gufw. You can run Gufw on any Linux distribution that has Python, GTK and ufw.
To allow ssh access in UFW you have to do the following. It’s that easy.
$ sudo ufw allow ssh/tcp

5. OpenBSD and PF

PF stands for packet filter. PF is licensed under BSD and developed on OpenBSD. PF firewall is installed by default on OpenBSD, FreeBSD, NetBSD.
PF does the following.
  • Packet Filtering
  • NAT
  • Traffic redirection (port forwarding)
  • Packet Queueing and Prioritization
  • Packet Tagging (Policy Filtering)
  • Excellent log capabilities
Additional information about PF:

Additional Firewall Software

Following are additional firewalls mentioned by readers along with the total number of votes it received.
  • CheckPoint FireWall-1 5
  • pfsense 5
  • Firestarter 5
  • Netfilter 4
  • SmoothWall Express 3
  • Guarddog 3
  • ipchain 3
  • Endian 2
  • Susefirewall 1
  • Cisco ASA/PIX 1
  • ClearOS 1
  • APF 1
  • Firewall Builder 1
  • Auto firewall in Puppy Linux 1
  • Drawbridge 1
  • Monowall 1
  • Firehol 1
  • SuSEfirewall2 1
  • Plesk 1