Linux / UNIX: Determine where a binary command is stored / located on file system

Posted on in Categories FreeBSD, Howto, Linux, Solaris, UNIX last updated August 29, 2007

You can use “type” or “whereis” command to find out which command shell executes and to print binary (command) file location for specified command.

whereis command example

Display ls command location along with man page path:
whereis ls
Output:
ls: /bin/ls /usr/share/man/man1p/ls.1p.gz /usr/share/man/man1/ls.1.gz

type command example

Find out which command the shell executes:
type -a ls
Output:
ls is aliased to `ls –color=tty’
ls is /bin/ls

Related: How Linux or UNIX Understand which program to run – PART I and How BASH Shell Command Search Sequence Works

Howto: Make consistent MySQL database backups using Solaris ZFS snapshots

Posted on in Categories Howto, MySQL, Solaris, UNIX last updated August 20, 2007

I’ve already written about MySQL backup using a shell script and consistent backup with Linux Logical Volume Manager (LVM) snapshots:

A snapshot volume is a special type of volume that presents all the data that was in the volume at the time the snapshot was created. This means you can back up that volume without having to worry about data being changed while the backup is going on, and you don’t have to take the database volume offline while the backup is taking place.

Niclas has posted a nice howto about consistent MySQL backups using Solaris UNIX ZFS snapshots:

In this article I will show you how to install MySQL on a ZFS file system and supply you with a script to make consistent snapshots of the databases. This script may not be 100% fit for busy sites but for most smaller places I think it is perfect.

Linux / UNIX: display time of different time zones using TZ environment variable

Posted on in Categories Debian Linux, FreeBSD, Gentoo Linux, Howto, Linux, RedHat/Fedora Linux, Solaris, Suse Linux, Sys admin, Tips, Ubuntu Linux, UNIX last updated July 25, 2007

Let us say you need to display time for different zones or cities. Sure you can use The World Clock – Time Zones located here. If you need a different time zone at a shell prompt or script use old good date command.

Different timezones can be displayed by changing the TZ environment variable.

TZ Specifies the timezone, unless overridden by command line parameters. If neither is specified, the setting from /etc/localtime is used by Linux/UNIX computer.

Display current date and timezone

$ date
Output:

Tue Jul 24 22:05:54 CDT 2007

Display time of different timezones using the date command and TZ variable

Set timezone to PDT:
$ export TZ=America/Los_Angeles
$ date

Output:

Tue Jul 24 20:12:01 PDT 2007

Or set timezone to IST:
$ export TZ=Asia/Calcutta
$ date

Output:

Wed Jul 25 08:46:12 IST 2007

Remove the TZ variable with unset command:
$ unset TZ
$ date

Output:

Tue Jul 24 22:17:31 CDT 2007

Read date,bash,unset command man page for more information. Hope this small tip will save your time and see a different time zone.

Related: Howto: Redhat enterprise Linux / CentOS setup DST – Daylight Saving Time

Will OpenSolaris repeat the Linux success again?

Posted on in Categories Solaris, Ubuntu Linux, UNIX last updated July 17, 2007

Project Indiana is a new project to create an OpenSolaris binary distribution. This distribution will focus on providing a single CD install with the basic core operating system and desktop environment, with the opportunity of installing additional software off network repositories just like Ubuntu Linux.

This is a new project from Sun. The main aim is make OpenSolaris an easy to use UNIX:

The distribution will showcase much of the work continuing in the OpenSolaris community and the best of breed open source software available within other open source communities. Moverover, the distribution will include work that closes the familiarity gap with existing GNU/Linux users eg. install and packaging.

Project Indiana will be a leading edge distribution with an expected adoption of OpenSolaris enthusiasts and developers on single user systems and basic server setups. It will also encourage new users coming to the platform for the first time.

According to Ian Murdock’s Weblog:

Like Linux, OpenSolaris is a kernel. Except that it’s more than a kernel. Or, rather, more than a kernel but not quite a complete operating system. Are you confused yet?

Ian is 100% right and suggests ways to improve OpenSolaris. In short Sun’s new project trying to turn OpenSolaris into a practical distributions, you can download OpenSolaris just like Ubuntu and use it like a pro. Now the million dollar question ~ Can OpenSolaris make Sun shine again?

Read more: Sun’s Project Indiana: turning OpenSolaris into a practical platform

ZFS on Linux using FUSE

Posted on in Categories File system, GNU/Open source, Linux, Solaris, UNIX last updated June 19, 2007

Linus Torvalds called ZFS one of the very few bright spots in Solaris. ZFS released under Sun’s Common Development and Distribution License. Linux is under GPL v2 which makes ZFS incompatible with Linux. I’ve used ZFS under Solaris and it is absolutely rocking file system.

Now this hot feature from OpenSolaris is taking a weird but working path to Linux inclusion using FUSE (Filesystem in Userspace).

If you like Linux for the long list of supported hardware but Solaris for the advanced new ZFS filesystem, a new development project might have a happy surprise for you. One advantage to putting ZFS into a separate daemon is the same as something that microkernel operating system developers have been talking up for years: You can kill and restart the filesystem independently of the operating system.

Check out official ZFS on FUSE blog and LinuxWorld article for more information ZFS on Linux: It’s alive

Howto: Connect MySQL server using C program API under Linux or UNIX

Posted on in Categories C Programming, FreeBSD, Gentoo Linux, Howto, Linux, MySQL, OpenBSD, RedHat/Fedora Linux, Solaris, Suse Linux, Tips, Ubuntu Linux, UNIX last updated May 31, 2007

From my mailbag:

How do I write a C program to connect MySQL database server?

MySQL database does support C program API just like PHP or perl.

The C API code is distributed with MySQL. It is included in the mysqlclient library and allows C programs to access a database.

Many of the clients in the MySQL source distribution are written in C. If you are looking for examples that demonstrate how to use the C API, take a look at these clients. You can find these in the clients directory in the MySQL source distribution.

Requirements

Make sure you have development environment installed such as gcc, mysql development package etc. Following is the list summarize the list of packages to compile program:

  • mysql: MySQL client programs and shared library
  • mysqlclient: Backlevel MySQL shared libraries (old libs)
  • mysql-devel: Files for development of MySQL applications (a must have)
  • mysql-server: Mysql server itself
  • gcc, make and other development libs: GNU C compiler

Sample C Program

Following instructions should work on any Linux distro or UNIX computer. Here is the small program that connects to mysql server and list tables from mysql database.(download link):

/* Simple C program that connects to MySQL Database server*/
#include <mysql.h>
#include <stdio.h>

main() {
   MYSQL *conn;
   MYSQL_RES *res;
   MYSQL_ROW row;

   char *server = "localhost";
   char *user = "root";
   char *password = "PASSWORD"; /* set me first */
   char *database = "mysql";

   conn = mysql_init(NULL);

   /* Connect to database */
   if (!mysql_real_connect(conn, server,
         user, password, database, 0, NULL, 0)) {
      fprintf(stderr, "%s\n", mysql_error(conn));
      exit(1);
   }

   /* send SQL query */
   if (mysql_query(conn, "show tables")) {
      fprintf(stderr, "%s\n", mysql_error(conn));
      exit(1);
   }

   res = mysql_use_result(conn);

   /* output table name */
   printf("MySQL Tables in mysql database:\n");
   while ((row = mysql_fetch_row(res)) != NULL)
      printf("%s \n", row[0]);

   /* close connection */
   mysql_free_result(res);
   mysql_close(conn);
}

How do I compile and link program against MySQL libs?

MySQL comes with a special script called mysql_config. It provides you with useful information for compiling your MySQL client and connecting it to MySQL database server. You need to use following two options.
Pass –libs option – Libraries and options required to link with the MySQL client library.

$ mysql_config --libs
Output:

-L/usr/lib64/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -L/usr/lib64 -lssl -lcrypto

Pass –cflags option – Compiler flags to find include files and critical compiler flags and defines used when compiling the libmysqlclient library.
$ mysql_config --cflags
Output:

-I/usr/include/mysql -g -pipe -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing

You need to pass above option to GNU C compiler i.e. gcc. So to compile above program, enter:
$ gcc -o output-file $(mysql_config --cflags) mysql-c-api.c $(mysql_config --libs)
Now execute program:
$ ./output-file
Output:

MySQL Tables in mysql database:
columns_priv
db
func
help_category
help_keyword
help_relation
help_topic
host
tables_priv
time_zone
time_zone_leap_second
time_zone_name
time_zone_transition
time_zone_transition_type
user 

References:

  • MySQL C API – A must read – official MySQL C API documentation

Howto Install and configure Solaris UNIX 10

Posted on in Categories Howto, Solaris, Sys admin, UNIX last updated May 4, 2007

This is a nice and visual guide for installing Sun Solaris UNIX version 10. From the article:

This is a very simple step by step set of instructions that will take you from boot through to running a browser. Everything you need to get started is here complete with easy to follow picture based instructions.

Section 1 : Hardware Selection
Section 2 : Boot the Installation CDROM or DVD
Section 3 : Basic Configuration Data including networking
Section 4 : Finally You Are Welcome to Install
Section 5 : After First Reboot
Section 6 : Reboot again
Section 7 : Login to the Desktop

Read: A Step by Step Guide to Installing Solaris 10

Download Solaris UNIX Intel x86 / Sparc Adobe Flash players

Posted on in Categories Download of the day, Links, Linux desktop, News, Solaris, UNIX last updated March 22, 2007

This is a good move, especially considering increase in AMD64 workstation from Sun.

From the official blog:

The fact that Flash Player 9 Unix support is presently limited to Linux/x86 has been the source of some consternation to the users of some non-Linux/non-x86 Unix systems. You may be interested to learn that Unix platform support has recently been expanded. There are now beta versions of Flash Player 9 available from Adobe Labs

Download Adobe Flash player for Sun Solaris

=> Get flashplayer for Solaris

You can find more details here (via penguin.swf)