Archive for October, 2007

Dennis Ritchie

October 26, 2007

Dennis MacAlistair Ritchie (born September 9, 1941) is an American computer scientist notable for his influence on ALTRAN, B, BCPL, C, Multics, and Unix. He received the Turing Award in 1983 and the National Medal of Technology in 1998. Ritchie is currently the head of Lucent Technologies‘ System Software Research Department.

Background

Born in Bronxville, New York, Ritchie graduated from Harvard with degrees in physics and applied mathematics. In 1967, he began working at the Bell Labs’ Computing Sciences Research Center.

C and Unix

Ritchie is best known as the creator of the C programming language and a key developer of the Unix operating system, and as co-author of the definitive book on C, The C Programming Language, commonly referred to as ‘K/R’ or K&R (in reference to the authors Kernighan and Ritchie).

Ritchie’s invention of C and his role in the development of Unix alongside Ken Thompson, has placed him as an important pioneer of modern computing. The C language is still widely used today in application and operating system development and its influence is seen in most modern programming languages. Unix has also been influential, establishing concepts and principles that are now well-established precepts of computing. The popular Linux operating system and its tools are descendants of Ritchie’s work and the Windows operating systems include Unix compatibility tools and C compilers for developers.

Ritchie has said that creating the C language ‘looked like a good thing to do’ and that anyone else in the same place at the same time would have done the same thing, though Bell Labs colleague Bjarne Stroustrup, developer of C++ said that ‘if Dennis had decided to spend that decade on esoteric math, Unix would have been stillborn’.

Following the success of Unix, Ritchie continued research into operating systems and programming languages with contributions to the Plan 9 and Inferno operating systems and the Limbo programming language.

Ken Thompson

October 26, 2007

Biography

Kenneth Lane Thompson (born February 4, 1943), commonly referred to as Ken Thompson (or simply Ken in hacker circles), is an American pioneer of computer science notable for his work with the B programming language and his shepherding the UNIX and Plan 9 from Bell Labs operating systems.

Thompson was born in New Orleans, Louisiana, U.S.. He received a Bachelor of Science in 1965 and Master’s degree in 1966, both in Electrical Engineering and Computer Science, from the University of California, Berkeley, where his Master’s thesis advisor was Elwyn Berlekamp.

In the 1960s, Thompson and Dennis Ritchie worked on the Multics operating system. While writing Multics, Thompson created the Bon programming language. The two left the Multics project as it was becoming too complex, but they took the lessons they learned to Bell Labs, where, in 1969, Thompson and Ritchie were the principal creators of the UNIX operating system. There, Thompson also wrote the B programming language, a precursor to Ritchie’s C.

Thompson had developed the CTSS version of the editor QED, which included regular expressions for searching text. QED and Thompson’s later editor ed (the default editor on Unix) contributed greatly to the eventual popularity of regular expressions, previously regarded mostly as a tool (or toy) for logicians. Regular expressions became pervasive in Unix text processing programs (such as grep), and even more modern programming languages like Perl. Almost all programs that work with regular expressions today use some variant of Thompson’s notation for them.

Along with Joseph Condon, he created the hardware and software for Belle, a chess computer. He also wrote programs for generating the complete enumeration of chess endings, for all 4, 5, and 6-piece endings, allowing chess-playing computer programs to make “perfect” moves once a position stored in them is reached. Later, with the help of chess endgame expert John Roycroft, Thompson distributed his first results on CD-ROM.

Thompson’s style of programming has influenced others, notably in the terseness of his expressions and a preference for clear statements.

In late 2000, Thompson retired from Bell Labs. He worked at Entrisphere, Inc as a fellow until 2006, and now works at Google as a Distinguished Engineer.

How to Automatically Upgrade Ubuntu

October 26, 2007

I’ve been using Ubuntu for nearly one year now. I have to say, its a great distro. Everything works well and immediately. I run it as a server on my PC.That said, it’s time to move on to the point of this post.

I like to have a completely updated installation. Most of you Ubuntu users know that apt-get can take quite awhile if you have a bunch of packages to install. This can be fixed easily. Basically you just use a cron job to run apt-get whenever you want it updated. I have mine to update every Monday night at midnight.

You’ll want to be root when you create the cron job so that apt-get can run properly.

The first thing you’ll need to do is open up your favorite text editor and enter the cron information into a file. I’m going to call mine apt-get.cron.file. In this file you’ll need to enter exactly when you want the cron to run, as well as what you want it to do.

As I said, I have mine run every Monday at midnight (00:00). My entry looks like this so far:

0 0 * * Mon

This tells cron to run on the 0th minute of the 0th hour of every Monday of every month. The next step is to specify the user (root). Your cron entry should now look like:

0 0 * * Mon root

The final step is to specify the commands you want to run. I want to run three: apt-get update, apt-get upgrade, and apt-get dist-upgrade. When specifying multiple commands, you should connection them with &&.

0 0 * * Mon root apt-get update && apt-get upgrade && apt-get dist-upgrade
After you have your cron job written how you want it to be, you need to actually create a job for it. Once it’s saved into a file all you need to do is run

nano /etc/crontab

and insert that line into this file.

After all this is set up, all you need to do is go about your business and never have to worry about updating your computer again!

.bash_history usage

October 23, 2007

I spend most of my time working in front of a black and white terminal of remote SSH connections to various servers. This means that I use bash (as my preferred shell) most of the day. And bash history is a very important feature of bash that saves me much time by recalling previous commands I have typed. Here are some tricks on how you can optimize with some simple configurations settings the usage your bash history.

1. Don’t save duplicates:
This is my favorite…

HISTCONTROL=ignoreboth

this causes any lines matching the previous history entry not to be saved.
Other options for HISTCONTROL: ignorespace, lines which begin with a space character are not saved in the history list; erasedups causes all previous lines matching the current line to be removed from the history list before that line is saved.

2. Size of the history:
HISTSIZE: The number of commands to remember in the command history. The default value is 500.

HISTSIZE=500

You can set this to 0 and disable the usage of the history file.

3. Others:
HISTFILE: The name of the file in which command history is saved. The default value is ~/.bash_history.
HISTIGNORE: A colon-separated list of patterns used to decide which command lines should be saved on the history list.

How do you set these options? Either export them in your environment in your personal bash configuration file (~/.bashrc) or in the global bash configuration file (/etc/bash.bashrc). The name of the configuration files can depend from your Linux distribution and bash version (the ones included are from Debian Linux), but you can always see your particular options using man bash. So, you can add in your configuration files the parameters you want like this:

export HISTCONTROL=ignoreboth
export HISTSIZE=500

You will need to restart your bash session in order to activate the settings. You can check if your configuration were entered correctly by typing env at the command prompt. If you don’t see your configuration in the environment variables than you have done something wrong. If you see your configuration option, then all is ok, and your setting is active already.

ldap user account update using a shell script

October 10, 2007

hi,

It is very easy to update ldap entry using a shell script.

function update_user_ldif {
user_name=$1

cat > $UPDATE_USER <<- TEMPLATE_LDIF
dn: uid=$user_name,ou=users,dc=aganith,dc=com
changetype: modify
replace: employeeType
employeeType: $emp_type

TEMPLATE_LDIF
}
ldapmodify -h $LDAP_HOST -w $LDAP_ROOT_PASSWD -D $ROOT_BIND_DN -x -f $UPDATE_USER

  • LDAP_HOST :- ldap server ip
  • LDAP_ROOT_PASSWD :- ldap access password
  • ROOT_BIND_DN :- account used for admin access. eg: cn=admin,dc=aganith,dc=com

use make with love

October 9, 2007

Hi,

Humor can be generated using make utility.

Unix make utility executes a list of shell commands associated with each target, typically to create or update a file of the same name. makefile contains entries that describe how to bring a target up to date with respect to those on which it depends, which are called dependencies.

We run make as :- make myprog

if error it gives make: *** No rule to make target `myprog’. Stop.

if u keep the name of program as love , we get very unique answer to it.

bash$  make love

make: *** No rule to make target `love’. Stop.

using time.h in c

October 5, 2007

Some header files in c are used very rarely in our daily routine. But if we wana log some thing, (In unix every thing has to be logged) , we have to write some code related to time management.

here is a code that can help u in writing time program to log ur data.

#include <stdio.h>		        /* NULL		       */
#include <time.h>		        /* ctime, asctime      */

main()
{
  time_t now;				/* define 'now'. time_t is probably
					 * a typedef	*/

				        /* Calender time is the number of
				         * seconds since 1/1/1970   	*/

  now = time((time_t *)NULL);		/* Get the system time and put it
   					 * into 'now' as 'calender time' */

  printf("%s", ctime(&now));		/* Format data in 'now'
					 * NOTE that 'ctime' inserts a
					 * '\n' */

   /*********************************************************************/

	/* Here is another way to extract the time/date information	*/

  time(&now);

  printf("%s", ctime(&now));		/* Format data in 'now'		*/

   /*********************************************************************/

  {
    struct tm *l_time;

    l_time = localtime(&now);		/* Convert 'calender time' to
					 * 'local time' - return a pointer
					 * to the 'tm' structure. localtime
					 * reserves the storage for us.	*/
    printf("%s", asctime(l_time));
  }

   /*********************************************************************/

  time(&now);
  printf("%s", asctime(localtime( &now  )));

   /*********************************************************************/

  {
    struct tm *l_time;
    char string[20];

    time(&now);
    l_time = localtime(&now);
    strftime(string, sizeof string, "%d-%b-%y\n", l_time);
    printf("%s", string);
  }
}

Mysql and C API

October 4, 2007

//Just a simple example to show that we can work with mysql using c language

// Happy programming
#include<my_global.h>
#include<my_sys.h>
#include<mysql.h>

static char *opt_host_name = “yourip”; //eg 192.168.0.254
static char *opt_user_name = “userdatabase”;
static char *opt_password = “userpassword”;
static unsigned int opt_port_num = 3306;
static char *opt_socket_name = NULL;
static char * opt_db_name = “dbname”;
static unsigned int opt_flags = 0;

static MYSQL *conn;

int main(int argc, char *argv[])
{
conn = mysql_init(NULL);

if(conn == NULL)
{
fprintf(stderr,”mysql init() failed\n”);
exit(1);
}

if(mysql_real_connect(conn,opt_host_name,opt_user_name,opt_password,

opt_db_name,opt_port_num,opt_socket_name,opt_flags) == NULL)
{
fprintf(stderr,”mysql_real_connect() failed\n”);
mysql_close(conn);
exit(1);

}
else
{
printf(“connected to mysql server on:%s\t”,opt_host_name);
}

mysql_close(conn);
return 0;
}

General Instructions for Building Client Programs

October 4, 2007

When you write a MySQL client program in C, you’ll need a C compiler, obviously.
The examples shown here use gcc, which is probably the most common compiler used
on Unix.You’ll also need the following in addition to the program’s own source files:

  • The MySQL header files
  • The MySQL client library

The header files and client library constitute the basis of MySQL client programming
support. If they are not installed on your system already, you’ll need to obtain them. If
MySQL was installed on your system from a source or binary distribution, client programming
support should have been installed as part of that process. If RPM files were
used, this support won’t be present unless you installed the developer RPM. Should you
need to obtain the MySQL header files and library

Compiling and Linking Client Programs

To compile and link a client program, you might need to specify where the MySQL
header files and client library are located, because often they are not installed in locations
that the compiler and linker search by default. For the following examples, suppose that
the header file and client library locations are /usr/local/include/mysql and
/usr/local/lib/mysql.
To tell the compiler how to find the MySQL header files when you compile a source
file into an object file, pass it an -I option that names the appropriate directory. For
example, to compile myclient.c to produce myclient.o, you might use a command
like this:
% gcc -c -I/usr/local/include/mysql myclient.c
To tell the linker where to find the client library and what its name is, pass
-L/usr/local/lib/mysql and -lmysqlclient arguments when you link the object file
to produce an executable binary, as follows:
% gcc -o myclient myclient.o -L/usr/local/lib/mysql -lmysqlclient
If your client consists of multiple files, name all the object files on the link command.
The link step may result in error messages having to do with functions that cannot be
found. In such cases, you’ll need to supply additional -l options to name the libraries
containing the functions. If you see a message about compress() or uncompress(), try
adding -lz or -lgz to tell the linker to search the zlib compression library:
% gcc -o myclient myclient.o -L/usr/local/lib/mysql -lmysqlclient -lz
If the message names the floor() function, add -lm to link in the math library.You
might need to add other libraries as well. For example, you’ll probably need -lsocket
and -lnsl on Solaris.

You can use the mysql_config utility to determine the proper flags for compiling
and linking MySQL programs. For example, the utility might indicate that the following
options are needed:
% mysql_config –cflags
-I’/usr/local/mysql/include/mysql’
% mysql_config –libs
-L’/usr/local/mysql/lib/mysql’ -lmysqlclient -lz -lcrypt -lnsl -lm
To use mysql_config directly within your compile or link commands, invoke it
within backticks:
% gcc -c `mysql_config –cflags` myclient.c
% gcc -o myclient myclient.o `mysql_config –libs`
The shell will execute mysql_config and substitute its output into the surrounding
command, which automatically provides the appropriate flags for gcc.
If you don’t use make to build programs, I suggest you learn how so that you won’t
have to type a lot of program-building commands manually. Suppose that you have a
client program, myclient, that comprises two source files, main.c and aux.c, and a
header file, myclient.h.You might write a simple Makefile to build this program as follows.
Note that indented lines are indented with tabs; if you use spaces, the Makefile
will not work.
CC = gcc
INCLUDES = -I/usr/local/include/mysql
LIBS = -L/usr/local/lib/mysql -lmysqlclient
all: myclient
main.o: main.c myclient.h
$(CC) -c $(INCLUDES) main.c
aux.o: aux.c myclient.h
$(CC) -c $(INCLUDES) aux.c
myclient: main.o aux.o
$(CC) -o myclient main.o aux.o $(LIBS)
clean:
rm -f myclient main.o aux.o
Using the Makefile, you can rebuild your program whenever you modify any of the
source files simply by running make, which displays and executes the necessary commands:
% make
gcc -c -I/usr/local/mysql/include/mysql myclient.c
gcc -o myclient myclient.o -L/usr/local/mysql/lib/mysql -lmysqlclient

That’s easier and less error prone than typing long gcc commands. A Makefile also
makes it easier to modify the build process. For example, if your system is one for which
you need to link in additional libraries such as the math and compression libraries, edit
the LIBS line in the Makefile to add -lm and -lz:
LIBS = -L/usr/local/lib/mysql -lmysqlclient -lm -lz
If you need other libraries, add them to the LIBS line as well.Thereafter when you
run make, it will use the updated value of LIBS automatically.
Another way to change make variables other than editing the Makefile is to specify
them on the command line. For example, if your C compiler is named cc rather than
gcc, you can say so like this:
% make CC=cc
If mysql_config is available, you can use it to avoid writing literal include file and
library directory pathnames in the Makefile.Write the INCLUDES and LIBS lines as follows
instead:
INCLUDES = ${shell mysql_config –cflags}
LIBS = ${shell mysql_config –libs}
When make runs, it will execute each mysql_config command and use its output to
set the corresponding variable value.The ${shell} construct shown here is supported
by GNU make; you might need to use a somewhat different syntax if your version of
make isn’t based on GNU make.
If you’re using an integrated development environment (IDE), you may not use a
Makefile at all.The details will depend on your particular IDE.

Reset Mysql password

October 3, 2007

How to Reset the Root PasswordIf you have never set a root password for MySQL, the server does not require a password at all for connecting as root. However, it is recommended to set a password for each account. See Section 5.6.1, “General Security Guidelines”.

If you set a root password previously, but have forgotten what it was, you can set a new password. The following procedure is for Windows systems. The procedure for Unix systems is given later in this section.

The procedure under Windows:

  1. Log on to your system as Administrator.
  2. Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager:
    Start Menu -> Control Panel -> Administrative Tools -> Services

    Then find the MySQL service in the list, and stop it.

    If your server is not running as a service, you may need to use the Task Manager to force it to stop.

  3. Create a text file and place the following command within it on a single line:
    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPassword');

    Save the file with any name. For this example the file will be C:\mysql-init.txt.

  4. Open a console window to get to the DOS command prompt:
    Start Menu -> Run -> cmd
  5. We are assuming that you installed MySQL to C:\mysql. If you installed MySQL to another location, adjust the following commands accordingly.

    At the DOS command prompt, execute this command:

    C:\> C:\mysql\bin\mysqld-nt --init-file=C:\mysql-init.txt

    The contents of the file named by the --init-file option are executed at server startup, changing the root password. After the server has started successfully, you should delete C:\mysql-init.txt.

    If you install MySQL using the MySQL Installation Wizard, you may need to specify a --defaults-file option:

    C:\> "C:\Program Files\MySQL\MySQL Server
    5.0\bin\mysqld-nt.exe"
             --defaults-file="C:\Program Files\MySQL\MySQL Server 5.0\my.ini"
             --init-file=C:\mysql-init.txt

    The appropriate --defaults-file setting can be found using the Services Manager:

    Start Menu -> Control Panel -> Administrative Tools -> Services

    Find the MySQL service in the list, right-click on it, and choose the Properties option. The Path to executable field contains the --defaults-file setting.

  6. Stop the MySQL server, then restart it in normal mode again. If you run the server as a service, start it from the Windows Services window. If you start the server manually, use whatever command you normally use.
  7. You should be able to connect using the new password.

In a Unix environment, the procedure for resetting the root password is as follows:

MySQL Enterprise.  For expert advice on security-related issues, subscribe to the MySQL Enterprise Monitor. For more information see http://www.mysql.com/products/enterprise/advisors.html.

  1. Log on to your system as either the Unix root user or as the same user that the mysqld server runs as.
  2. Locate the .pid file that contains the server’s process ID. The exact location and name of this file depend on your distribution, hostname, and configuration. Common locations are /var/lib/mysql/, /var/run/mysqld/, and /usr/local/mysql/data/. Generally, the filename has the extension of .pid and begins with either mysqld or your system’s hostname.

    You can stop the MySQL server by sending a normal kill (not kill -9) to the mysqld process, using the pathname of the .pid file in the following command:

    shell> kill `cat /mysql-data-directory/host_name.pid`

    Note the use of backticks rather than forward quotes with the cat command; these cause the output of cat to be substituted into the kill command.

  3. Create a text file and place the following command within it on a single line:
    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPassword');

    Save the file with any name. For this example the file will be ~/mysql-init.

  4. Restart the MySQL server with the special --init-file=~/mysql-init option:
    shell> mysqld_safe --init-file=~/mysql-init &
    

    The contents of the init-file are executed at server startup, changing the root password. After the server has started successfully you should delete ~/mysql-init.

  5. You should be able to connect using the new password.

Alternatively, on any platform, you can set the new password using the mysql client(but this approach is less secure):

  1. Stop mysqld and restart it with the --skip-grant-tables --user=root options (Windows users omit the --user=root portion).
  2. Connect to the mysqld server with this command:
    shell> mysql -u root
  3. Issue the following statements in the mysql client:
    mysql> UPDATE mysql.user SET Password=PASSWORD('
    newpwd')
        ->                   WHERE User='root';
    mysql> FLUSH PRIVILEGES;

    Replace “newpwd” with the actual root password that you want to use.

  4. You should be able to connect using the new password.