Wednesday, October 24, 2007

What is Embedded Linux?

Embedded Linux 

Embedded Linux is the designation for Linux-based operating systems that are used as embedded operating systems in cell phones, personal digital assistants, media player handsets and other consumer electronics devices. Linux is also suitable for other embedded applications such as networking equipment, machine control, industrial automation, navigation equipment, and medical instruments.

Embedded Linux can be characterized as different from desktop and server versions of Linux in that embedded Linux is designed for devices with comparably limited resources, such as smaller sizes of RAM and much more limited secondary storage. Embedded Linux based devices frequently involve flash memory based secondary storage instead of a hard disk. Embedded Linux is scale down version of Linux operating systems.

Wednesday, August 29, 2007

Windows notepad bug!!!

Try this...

For those of you using Windows, do the following:

1.) Open an empty notepad file
2.) Type "Bush hid the facts" (without the quotes)
3.) Save it

4.) Close it, and re-open it.

Any explanation to the above?

Saturday, August 4, 2007

Recover root password in Linux

Recover root password


If you forgot your root password on Linux, recovering root password can be done
by booting Linux under a specific mode: single user mode.

This tutorial will show how to boot Linux in single user mode when using GRUB
and finally how to change root password.

Entering single user mode:

In GRUB select kernel you want to boot and hit 'e' to edit the line.
Select the kernel line and hit 'e' again to edit thet line.
Now add '1' or write 'single' to the end of line, and press enter
and then press 'b' to boot system.

This will make you the "root" user without asking for a password. Once the
system has booted, you can change the root password using the password
command.

Command to change password: passwd

Friday, August 3, 2007

Debugging Shell Script in Linux.


Bash shell offers debugging options which can be turn on or off using set command.

Execution Trace
set -x : Display commands and their arguments as they are executed.

Verbose Mode
set -v : Display shell input lines as they are read.

Syntax Checking
set -n : Reads all commands, but does not execute them.

You can use above commands in shell script itself:

#!/bin/bash
pwd
ls
# turn on debug mode
set -x
if [ -f "/home/user/file.txt" ]; then
echo "Error reading file: /home/user/file.txt"
exit 1
fi
# turn OFF debug mode
set +x
ls
# more commands.


You can replace standard

#!/bin/bash

with (for debugging)
#!/bin/bash -xv


Monday, July 2, 2007

MySQL Identifier Case Sensitivity


Identifier Case Sensitivity

In MySQL, databases correspond to directories within the data directory.
Each table within a database corresponds to at least one file within the
database directory (and possibly more, depending on the storage engine).
Consequently, the case sensitivity of the underlying operating system
determines the case sensitivity of database and table names. This means
database and table names are case sensitive in most varieties of Unix, and not
case sensitive in Windows. One notable exception is Mac OS X, which is
Unix-based but uses a default filesystem type (HFS+) that is not case
sensitive. However, Mac OS X also supports UFS volumes, which are case
sensitive just as on any Unix. See

Section 1.9.4, “MySQL Extensions to Standard SQL”
. The
lower_case_table_names system variable also
affects how the server handles identifier case sensitivity, as described later
in this section.

MySQL Enterprise.
lower_case_table_names
is just one of the system variables monitored by
the MySQL Network Monitoring and Advisory Service. For information about
subscribing to this service see,

http://www.mysql.com/products/enterprise/advisors.html
.


Note: Although database and
table names are not case sensitive on some platforms, you should not refer to
a given database or table using different cases within the same statement. The
following statement would not work because it refers to a table both as
my_table and as MY_TABLE:


mysql> SELECT * FROM my_table WHERE MY_TABLE.col=1;

Column, index and stored routine names are not case sensitive on any
platform, nor are column aliases. Trigger names are case sensitive.


By default, table aliases are case sensitive on Unix, but not so on Windows
or Mac OS X. The following statement would not work on Unix, because it refers
to the alias both as a and as
A:


mysql> SELECT col_name FROM tbl_name AS a
-> WHERE a.col_name = 1 OR A.col_name = 2;

However, this same statement is permitted on Windows. To avoid problems
caused by such differences, it is best to adopt a consistent convention, such
as always creating and referring to databases and tables using lowercase
names. This convention is recommended for maximum portability and ease of use.


How table and database names are stored on disk and used in MySQL is
affected by the lower_case_table_names system
variable, which you can set when starting mysqld.
lower_case_table_names can take the values shown
in the following table. On Unix, the default value of
lower_case_table_names
is 0. On Windows the default value is 1. On Mac
OS X, the default value is 2.


















ValueMeaning
0Table and database names are stored on disk using the lettercase
specified in the CREATE TABLE or
CREATE DATABASE statement. Name comparisons
are case sensitive. Note that if you force this variable to 0 with
--lower-case-table-names=0 on a
case-insensitive filesystem and access MyISAM
tablenames using different lettercases, index corruption may result.
1Table names are stored in lowercase on disk and name comparisons are
not case sensitive. MySQL converts all table names to lowercase on
storage and lookup. This behavior also applies to database names and
table aliases.
2Table and database names are stored on disk using the lettercase
specified in the CREATE TABLE or
CREATE DATABASE statement, but MySQL
converts them to lowercase on lookup. Name comparisons are not case
sensitive. Note: This works
only on filesystems that are not
case sensitive! InnoDB table names are
stored in lowercase, as for lower_case_table_names=1.

If you are using MySQL on only one platform, you don't normally have to
change the lower_case_table_names variable.
However, you may encounter difficulties if you want to transfer tables between
platforms that differ in filesystem case sensitivity. For example, on Unix,
you can have two different tables named my_table
and MY_TABLE, but on Windows these two names are
considered identical. To avoid data transfer problems stemming from lettercase
of database or table names, you have two options:


  • Use lower_case_table_names=1 on all
    systems. The main disadvantage with this is that when you use
    SHOW TABLES or SHOW
    DATABASES
    , you don't see the names in their original lettercase.

  • Use lower_case_table_names=0 on Unix and
    lower_case_table_names=2 on Windows. This
    preserves the lettercase of database and table names. The disadvantage of
    this is that you must ensure that your statements always refer to your
    database and table names with the correct lettercase on Windows. If you
    transfer your statements to Unix, where lettercase is significant, they do
    not work if the lettercase is incorrect.

    Exception: If you are using
    InnoDB tables, you should set
    lower_case_table_names to 1 on all platforms
    to force names to be converted to lowercase.

Note that if you plan to set the
lower_case_table_names
system variable to 1 on Unix, you must first
convert your old database and table names to lowercase before restarting
mysqld with the new variable setting.

Object names may be considered duplicates if their uppercase forms are
equal according to a binary collation. That is true for names of cursors,
conditions, functions, procedures, savepoints, and routine local variables. It
is not true for names of columns, constraints, databases, statements prepared
with PREPARE, tables, triggers, users, and
user-defined variables.

Wednesday, June 27, 2007

What you need to get started with PHP


Before you can write and test your PHP scripts, there's one thing you'll need - a server! Fortunately, you don't need to go out and buy one. In fact, you won't be spending any extra money. That's why PHP is so popular! But because PHP is a server-sided scripting language, you either have to get some web space with a hosting company that supports PHP, or make your computer pretend that it has a server installed. This is because PHP is not run on your PC - it's executed on the server. The results are then sent back to the client PC (your computer).

Don't worry if this all sounds a little daunting - we've come across an easier way to get you up and running. We're going to be using some software called "EasyPHP". This allows you to test your PHP scripts on your own computer. Over a million people have downloaded this software. It installs everything you need, if you have a Windows PC (Win9x/Me/NT/2000/XP). We'll explain how to get it installed in a moment, and where to get it from. But just a word for non-windows users.

Apple Users

If you have OS 10, then try this guy's site to get up and running with PHP. The link to click on is "PHP Apache Module (NEW version 5)"
http://www.entropy.ch/software/macosx/

Another useful page is:
http://farm.tucows.com/blog/_archives/2004/7/20/108833.html

You can also have a look at this site:
http://www.phpmac.com/browse.php?type=tut&cat=2


Linux Users

There's quite a few sites out there to help Linux users get up and running with the Apache server and PHP. Here's two sites that are worth checking out:

http://www.e-gineer.com/v1/instructions/install-php4x-for-apache1xx-on-linux.htm

http://www.phpfreaks.com/tutorials/12/0.php

If you know any better ones, we'd be interested in hearing from you!


Windows Users

OK, back to Easy PHP and Windows. First, you need to download the software. You can get it from here (this site is nothing to do with ours, by the way):


Download Easy PHP

Be sure to click the link for Installation Guide, as well as the link for Downloads. The file you need to download is EasyPHP. Once you have downloaded the file, double click to install.

Quick Tips to Optimize MySQL

Speed up your web application!

Since MySQL optimization is a significant topic and often specific to your application, let’s instead focus on obtaining some quick results that can lead to more in-depth investigation and customization.

First, you should also deploy MySQL on the right hardware. MySQL is memory hungry, so install as much RAM as you can afford. Once installed, tune MySQL to use memory for its various buffers. Fast disks and sufficient CPU are next, respectively.

Next, the official MySQL binaries, unlike many applications, come extremely well-tuned. If you’re not an expert user, you are almost certainly better off using the packages pre-built for your platform.

On the topic of packages, many distributions ship with MySQL pre-installed. This is convenient, but may not allow you to stay current with the latest stable version of MySQL. You’ll need to make a decision on whether it’s best for your organization to forgo distribution support for MySQL (say, if you’re using an enterprise distribution) and benefit from the enhancements and bug fixes provided by MySQL AB. If you’re not using a distribution that comes with a support contract, this may be less of a concern.

Regardless of which option you choose, you may find that you lack a MySQL configuration file present, which results in general, default settings. By default, MySQL is extremely resource-friendly, but that can be a performance killer. If you don’t have an /etc/my.cnf file, creating one should be your first step in tuning.

What settings to change and the values of those parameters are specific to your hardware and workload, so you’ll need to do some research to find your own optimal settings. How do you know if your settings are appropriate?

Two tools can help you deduce an answer: mytop and mysqlreport. The former is described online at http://www.linux-mag.com/2001-12/mysql_01.html; mysqlreport transforms the values from the SHOW STATUS command into an easy-to-read report that provides an in-depth understanding of how MySQL is running. You can download mysqlreport from http://hackmysql.com/mysqlreport.
Spend a little time experimenting and reading the MySQL documentation and benchmark your changes with mytop and mysqlreport.

Once you know MySQL is running like a well-oiled machine, there are other things you can do to improve performance.

*Be sure to enable the query cache — but also be sure that you’re code takes advantage of that cache. The cache for a table is invalidated every time the table is written to. Hence, if you write to a table to update a timestamp with every page view, the cache is almost of no use. One way to avoid “cache misses” is to create a HEAP table, write the timestamps to that table, and then regularly batch the updates to your main table.

*Remember that MySQL optimization goes beyond just tuning mysqld. You should also look closely at query optimization and making sure you have the proper indexes on your tables. An errant JOIN, even on relatively small tables, can result in a huge dataset being returned and significant table locking. Using EXPLAIN will help you better understand how MySQL will process the query you are looking into.

*If you’re not sure which queries to optimize, enable the slow query log, which logs queries that take more than a specified amount of time. By focusing on slow queries in your real world environment, you can hasten overall, actual performance.

*Mix MySQL storage engines on a per-table basis. You can use MyISAM tables for heavily read tables or for tables that require FULLTEXT search. Use InnoDB tables if you need row level locking and transactions.

*If you reach the maximum capacity of a single machine, replicate your databases to multiple machines. Send all writes to the single master and distribute the reads to as many slaves as you need to keep up with demand.

Even simple, gross optimization efforts like the ones described here can make a remarkable difference. With appropriate hardware and a little work, MySQL scales much further than it did just a few years ago, and is now powering some of the busiest sites on the web.

-from http://www.linux-mag.com.

Linux Magic SysRq Key

What is the "Magic" SysRq key?

According to the Linux kernel documentation:

It is a 'magical' key combo you can hit which the kernel will respond to regardless of whatever else it is doing, unless it is completely locked up.

The sysrq key is one of the best (and sometimes the only) way to determine what a machine is really doing. It is useful when a system appears to be "hung" or for diagnosing elusive, transient, kernel-related problems.

How do I enable and disable the SysRq key?
To use it, you need to have it enabled in your kernel (CONFIG_MAGIC_SYSRQ).
It usually is.
For security reasons, Red Hat Enterprise Linux disables the SysRq key by default. To enable it, run:
# echo 1 > /proc/sys/kernel/sysrq

To disable it:

# echo 0 > /proc/sys/kernel/sysrq

To enable it permanently, set the kernel.sysrq value in /etc/sysctl.conf to 1. That will cause it to be enabled on reboot.
kernel.sysrq = 1
Since enabling sysrq gives someone with console access extra abilities, it is recommended to disable it when not troubleshooting a problem or to ensure that console access is properly secured.

How do I trigger a sysrq event?
There are several ways to trigger a sysrq event. On a normal system, with an AT keyboard, sysrq events can be triggered from the console with the following key combo:

Alt+PrintScreen+ [CommandKey]


For instance, to tell the kernel to dump memory info (command key "m"), you would hold down the Alt and Print Screen keys, and then hit the m key.
Note that this will not work from an XWindows screen. You should first change to a text virtual terminal. Hit Ctrl+Alt+F1 to switch to the first virtual console prior to hitting the sysrq key combo.
On a serial console, you can achieve the same effect by sending a Breaksignal to the console and then hitting the command key within 5 seconds.
If you have a root shell on the machine (and the system is responding enough for you to do so), you can also write the command key character to the /proc/sysrq-trigger file. This is useful for triggering this info when you are not on the system console or for triggering it from scripts.

# echo 'm' > /proc/sysrq-trigger

If you find that holding three keys is difficult, you do have some other choices. You can trigger it manually:
echo t > /proc/sysrq-trigger

Or, you can make the Alt-SysRq "sticky" by:
echo 1 > sysrq-sticky

With that done, you can hold Alt-SysRq, release it, and then leisurely press "t" or whatever key you wanted.

You could also change the SysRq itself in /proc/sys/kernel/sysrq-key (it's normally 84 - Alt-SysRq for Intel).


When I trigger a sysrq event that generates output, where does it go?


When a sysrq command is triggered, the kernel will print out the information to the kernel ring buffer and to the system console. This information is normally logged via syslog to /var/log/messages.
Unfortunately, when dealing with machines that are extremely unresponsive, syslogd is often unable to log these events. In these situations, provisioning a serial console is often recommended for collecting the data.

What sort of sysrq events can be triggered?

There are several sysrq events that can be triggered once the sysrq facility is enabled. These vary somewhat between kernel versions, but there are a few that are commonly used:
· m - dump information about memory allocation
· t - dump thread state information
· p - dump current CPU registers and flags
· c - intentionally crash the system (useful for forcing a disk or netdump)
· s - immediately sync all mounted filesystems
· u - immediately remount all filesystems read-only
· b - immediately reboot the machine
· o - immediately power off the machine (if configured and supported)

Alt+SysRq+r takes keyboard and mouse control from the X server. This can be useful if the X-Server crashed, you can change to a console and kill the X-Server or check the error log.
Alt+SysRQ+k kills all processes on the current terminal. Its a bad idea to do this on a console where X is running. The graphic will stop and you cant see what you type.
Alt+SysRQ+b is like a reset: a reboot without umounting or sync.
Alt+SysRQ+o shuts down via APM.
Alt+SysRQ+s writes all data from the disc cache to the hard discs, its a sync.
Alt+SysRQ+u remounts all mounted file system read-only. After using this key, you can reboot the system with Alt+SysRQ+b without harming the system.
Alt+SysRQ+m prints memory information to the console.
Alt+SysRQ+e sends SIGTERM to all processes except init.
Alt+SysRQ+i sends SIGKILL to all processes except init.
Alt+SysRQ+l sends SIGKILL to all processes, inclusive init. (The system is not working after using this.)...
Linux is very stable, but sometimes a kernel panic could happen, sometimes this stops the X-server and you can’t change to the console. What should be done? Hitting the reset button and risk filesystem integrity?
NO! There is a possibility to shut down the system cleanly or find out the source of the kernel panic.
To shut down the system after a really bad kernel panic, do the following:
Alt+SysRQ+e (sends TERM-signal, processes can shutdown properly (e.g. save data))
Alt+SysRQ+u (a sync will be done when unmounting anyway)
Alt+SysRQ+i (for the processes that didn't listen for the TERM signal, this is a kill -9 process)
Alt+SysRQ+b (reboot).

Monday, June 11, 2007

PHP(Part: III):-MySQL Installation

MySQL 4.1
1.Download MySQL v4.1
Download MySQL from http://dev.mysql.com/downloads/mysql/4.1.html Just make sure you get a Windows Essentials (x86) binary version. (after you click "pick a mirror," skip all the questions part and scroll down to the mirrors list)
My file was named: mysql-essential-4.1.22-win32.msi
2.Install MySQL v4.1
  • Run the MSI file and use the following settings
  • Typical Setup
  • Skip Sign-Up
  • make sure "Configure the MySQL Server now" is checked
  • "Detailed Configuration"
  • "Developer Machine"
  • "Multifunctional Database"
  • "InnoDB Tablespace Settings" - leave everything default
  • "Decision Support (DSS)/OLAP"
  • make sure "Enable TCP/IP Networking" is checked and leave the port number at 3306 (at this point, if you have a firewall, it will usually try to access itself on the localhost)
  • "Standard Character Set"
  • check "Install As Windows Service"
  • enter your root password and I would recommend leaving "Enable root access from remote machines" unchecked
  • then hit "execute" and it'll install and set it up.

3.Getting PHP5 to work with MySQL -

Unfortunately PHP5 removed built-in support for MySQL. To get it to work, the easiest way is to copy the mysql library file by hand. Open the folder you unzipped your PHP to. Copy the libmysql.dll file (should be located like E:\php\libmysql.dll ) into your Window's System folder (usually C:\Windows\System32\ although might be C:\WinNT\System\ or something).

Then open up your php.ini in a text editor and search for ;extension=php_mysql.dll and remove the ; infont of that line

Restart Apache and see if you get any errors. If it complains about "php_mysql.dll" either your extension directory isn't correct or windows can't find libmysql.dll

Testing MySQLTesting MySQL is not exactly easy. However, here are the common connection strings for PHP and CGI. I recommend downloading phpMyAdmin and using it to create and manage your databases, etc.

PHP Connection test

?>?>?>?>?>?>

PHP(Part: II):-PHP Installation

PHP 5

1.Download & Unpack


1.Download and install PHP from http://www.php.net/downloads.php, you should grab the newest 5.x.x Windows Binary zip package that will work on apache.My file was named: php-5.2.0-Win32.zip

2.Unzip php. In my case, I unzipped to:e:\php\

3.Rename e:\php\php.ini-dist it to php.ini
4.Edit your php.ini

Open php.ini in a text editor and scroll down about halfway through the file and look for doc_root then change it to point to whatever your Apache DocumentRoot is set to.

In my case: doc_root = "e:\public_html"

Scroll down about 7 more lines and change the extension_dir from extension_dir = "./" to the location of the ext directory after you unzipped PHP.
In my case: extension_dir = "e:\php\ext"
If you are going to be using your server for testing, i recommend (this is optional) you search and change the error reporting to give you info on any errors, notices, or bad coding. If you want to enable this type of stuff, search for error_reporting for and change:

error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT
to
error_reporting = E_ALL E_NOTICE E_STRICT
5.Editing Apache Conf File

Using Notepad open e:\Apache2_2\conf\httpd.conf
(in the start-menu there should also be a "Edit the Apache HTTP Server httpd.conf Configuration File" shortcut).

Either at the very beginning or end of the file add the following lines: (NOTE: be sure to change BOTH e:/php parts to the directory you installed your php to)

LoadModule php5_module "e:/php/php5apache2_2.dll"

AddType application/x-httpd-php .php

PHPIniDir "e:/php"
6.[OPTIONAL] Editing Apache Conf File (part 2)

To get apache to automatically look for an index.php, search httpd.conf for DirectoryIndex (about line 212) and add the files you want apache to look for when a directory is loaded (if it doesn't find any of these files, it displays folder contents). Mine looks like:

DirectoryIndex index.php index.html default.html
7.Testing

Restart Apache if it is already running (if it doesn't start or you get errors, use your Apache "Test Configuration" shortcut in the Start Menu to see why).

To test your PHP simply create a test.php file in your Apache "DocumentRoot" folder (E:\public_html\ in my case). In your test.php file, type these 3 lines and then load the file in your browser like http://localhost/test.php (you should get a whole long list of php variables, settings, etc):


8.Documentation Suggestion

One weird thing I have noticed about PHP is that it does not come with documentation of any kind. If you are a php developer/programmer, I suggest you download the documentation. Downloads can be found on http://www.php.net/download-docs.php and I personally recommend the "English - Windows HTML Help" (chm) version as the search is so handy, although they all contain the same information.

PHP (Part: I):-Apache Installation

Apache 2.2.X:-

1.Download & Unpack

Download and install Apache from http://httpd.apache.org/download.cgi. Look for the "Win32 Binary (MSI Installer)" version. (you might want to change the download mirror first to get better speeds)

My file was named: apache_2.2.4-win32-x86-no_ssl.msi


2.Install

When you install Apache, you'll get a prompt for "Server Information." Here is the settings I used:Network Domain: localhost
Server Name: localhost
Admin Email: (your any email)
[checked]: for All Users, on Port 80, as a Service

3.Starting/Stopping Apache

After installing, Apache2 automatically starts. The icon in the System Tray means it started. The icon means the "Monitor Apache Servers" is running, but Apache2 isn't started.You can easily start/stop/restart Apache and Apache2 via that icon in your System Tray. If you get "The requested operation has failed!" error while starting apache use the "Test Configuration" shortcut in the Start Menu to find the error (if the text window pops up then closes before you can read it, your config file is fine).

4.Testing

Now the ultimate test. To see if it's serving. Open your browser and head to: http://127.0.0.1/ or http://localhost/If it shows the It works! you have your server software installed and running.

5.Making Apache point to your files

Using Notepad open E:\Apache2_2\conf\httpd.conf (in the start-menu there should also be a "Edit the Apache HTTP Server httpd.conf Configuration File" shortcut) and search for DocumentRoot. Change it from something like DocumentRoot "E:/Apache2_2" to the location where your HTML files and site are located. In my case: DocumentRoot "E:/public_html"


6.Then scroll down about one page and change: to point to the same location you set DocumentRoot to in the last step. Restart apache to make the changes take effect

Search About OpenSource

Google