Friday, November 7, 2008

Saving History To Another File

santo asked: "Is there any way to save the history command automatically in any other file in every 5min, can we do it through crond,if yes plz do so for me"

This is quite simple and you don't need cron. In 3 easy steps...

First, add shopt -s histappend to your bashrc to get history appended on bash session exit.

Next, make sure you have export HISTCONTROL=erasedups there to have no duplicate entries.

Finally use a large number in export HISTSIZE= i.e. 25000.

This will give you a large .bash_history file that you can search and back-up as needed.

Friday, September 12, 2008

How to Participate in the Linux Community

Have you ever wanted to know how to participate in the Linux community?

Red Hat Linux File Systems

Yes, I've been slacking again. Mostly I've been trying to figure what topic to cover next. I decided to take a closer look at the Linux file system, especially for the users who are new to Linux.

A typical Red Hat Linux system holds many directories and files. To efficiently administer such a system, you must know where important files and what kinds of files are stored. This chapter describes the Red Hat Linux file system layout, which generally follows the recommendations of the File System Hierarchy Standard.

Like other Unix systems, Red Hat Linux has a hierarchical file system. The top-most directory—known as the root directory—of the file system contains several other directories, sometimes called subdirectories. These directories in turn generally contain subdirectories and files.

The directory structure is not arbitrary. For packages to work properly, the location of important files and directories must be standardized. The File System Hierarchy Standard codifies common practices and suggests improved practices for the structure of directories. The File System Hierarchy Standard is available via the Web, at http://pathname.com/fhs.

Though designed with Linux systems in mind, the standard is applicable to Unix systems generally. Distributors of Linux generally follow the recommendations of the File System Hierarchy Standard. However, the standard is somewhat loose and subject to interpretation. Consequently, two distributions that are held to follow the standard may nevertheless differ significantly in the structure of their file systems. Red Hat Linux follows the standard closely. The Official Red Hat Linux Reference Guide explains the standard and how Red Hat Linux implements the standard’s recommendations.

Over the next several posts, we'll look at the standard directories of a Red Hat Linux system.

Saturday, August 16, 2008

Building Red Hat Enterprise RPMs

Red Hat makes source RPMs freely available at ftp.redhat.com/You can find the SRPMs for RHEL 5 Server in the /pub/redhat/linux/enterprise/5Server/en/os/SRPMS directory. If you're working with RHEL 5 Desktop, substitute 5Client for 5Server.

If you're studying for the Red Hat exams using a "rebuild," you don't have to buy RHEL. Alternatively, you can build Red Hat Enterprise RPMs from the source code. For example, you can learn more about the Samba server from the Samba source code. To do so, take the following steps. First, navigate to ftp.redhat.com (or a mirror site) and navigate to the directory with RHEL 5 source RPMs. (The source code for the RHEL 5 Client and Server are identical, as of this writing). Then you can

1. Down the RHEL 5 version of the package that contains the Samba server, samba-*.src.rpm.

2. Install the source RPM package. The rpm command described earlier sets up the source code in your /usr/src/redhat tree.

3. Build the RPM from source. The rpmbuild commands use the code loaded in the /usr/src/redhat directories to create RPM packages in the /usr/src/redhat/RPMs directory, in the subdirectory associated with your architecture.

Friday, August 15, 2008

Building Custom Source and Binary RPMs

By now, you should understand where you should modify a source RPM spec file to change compile-time options in the %build section. However, there's much more to building customized RPMs. Once you have modified the spec file, you need to tell RPM to build a new binary and source RPM.

You can build an RPM using the rpmbuild command, with the build switch, -b. By itself, rpmbuild -b calls the scripts specified in the %prep, %build, and %install section of the spec file. Normally, you'll modify the -b with a, which makes RPM go through the build process, step by step. The rpmbuild command is directed at a spec file. For example, this command

# rpmbuild -ba vsftpd.spec

directs RPM to create binary and source RPMs from this spec file. Alternatively, if you just want the binary RPM, use the following commands:

# rpmbuild -bb vsftpd.spec

Naturally, the RPMs are created in the RPMs/ and SRPMS/ subdirectories.

Thursday, August 14, 2008

Changing Compile Options for a Source RPM

Continuing from May 21, 2008...

While most precompiled RPMs will serve your needs, at times you will want to modify the source code or compile options in the corresponding SRPMs. You can do so in the spec file that you get when you installed the source RPM. Let's looking at the directories and their purpose.

/usr/src/redhat/SOURCES - Contains the original program source code.

/usr/src/redhat/SPECS - Contains spec files, which control the RPM build process

/usr/src/redhat/BUILD - Source code is unpacked and built here

/usr/src/redhat/RPMS - Contains the output binary RPM

/usr/src/redhat/SRPMS - Contains the SRPM created by the build process

To change the compile options in an SRPM, you must understand spec files. The spec file is stored in /usr/src/redhat/SPECS/packagename.spec. The spec file controls the way a package is built and what actions are performed when it is installed or removed from a system. A spec file has 10 different sections (see the list below). Several of the sections include commands that can be run as individual shell scripts. You won't see all of these sections every spec file. For more information, see the RPM HOWTO at www.rpm.org.

%preamble - Includes informaton shown with an rpm -qi command. This normally includes a summary, version, and group. It also includes a list of dependent packages.

%description - A basic package description.

%pre - Adds a macro for preinstallation scripts.

%prep - Includes any preparatory commands required before building the source code, such as unpacking.

%build - Commands to compile the spec file and build sources.

%install - Commands to install the software on a system.

Install and uninstall scripts - Spec files usually contains cripts that will be run on the end user's system to insall or remove the software. RPM can execute a script before the package is installed, after the package is installed, before the package is removed, and after the package is removed.

%verify - Although RPM takes care of most verifictaion tasks, a script can be inserted here for any desired extra checks.

%clean - A script can be specified here to perform any necessary cleanup tasks.

%post - Adds a macro that cleans up after installation.

%preun - Scripts that prepare for uninstallation.

%postrun - Adds a macro that cleans up after installation.

%files - A list of files in the package.

%changelog - A list of revisions.

You can change the compile-time options for a package in the build section of the spec file. Here's a sample %clean section from a different spec file (this is not from the vsftpd RPM):

%build
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/usr/bin $RPM_BUILD_ROOT/etc
./configure --prefix=/usr/ --exec-prefix=/
make CFLAGS="$RPM_OPT_FLAGS" LDFLAGS=-s

This section, a shell script, begins with some housekeeping, removing any files that may be left over from a previous build. A directory structure is created for the source files. Then the package is configured and compiled with the make command.

For a different package, you might modify the make command line to compile other components after LDFLAGS. The compile options from $RPM_OPT_FLAGS are defaults, set by RPM. Alternatively, you could use this variable to set other compile-time options such as a different CPU.

Note: Perhaps the essential reference guide to the RPM system is Red Hat's book Maximum RPM. An older version is available online from Red Hat at www.redhat.com/docs/books/max-rpm.

Wednesday, August 13, 2008

Red Hat Enterprise Linux 5 Tech Notes

Hi

I'm sorry that I've been away. I've been working on a book, and needed some time to finish it.

The PDF can be downloaded for free (as in beer). You may also purchase a printed version from Lulu.com.

I'll be picking up the blog next week.

-HackingRHEL

Wednesday, May 21, 2008

The /usr/src/redhat Directory Structure

There are five subdirectories located under the /usr/src/redhat directory, as described below
  • /usr/src/redhat/SOURCES contains the original program source code
  • /usr/src/redhat/SPECS contains spec files, which control the RPM build process
  • /usr/src/redhat/BUILD, source code is unpacked and built here
  • /usr/src/redhat/RPMS contains the output binary RPM
  • /usr/src/redhat/SRPMS contains the SRPM created by the build process
When you build a source RPM, you build it within this structure. If you install a source RPM, it is extracted into this structure. The kernel source RPM that you installed in the "Installing Source RPMs" should have unpacked a kernel-2.6.spec file in the /usr/src/redhat/SPECS directory.

Tuesday, May 20, 2008

Installing Source RPMs

Like normal RPMs, a source RPM (SRPM) is installed with the rpm -i rpmname.src.rpm command. However, this command installs only the contents of the SRPM in the various /usr/src/redhat subdirectories, which you can then use to create a binary RPM. for the purpose of our discussion on SRPM, I've installed the source for the Linux kernel from the freely available RHEL source RPMs, which you can download for yourself from ftp.redhat.com.

Once downloaded from the source of your choice, proceed to install it as if it were a regular RPM, in this case with the following command:

# rpm -ivh kernel-*.src.rpm

As noted earlier, you can now use the source code and spec files in various /usr/src/redhat subdirectories to build and install the package.

Monday, May 19, 2008

Creating Custom RPMs from Source

A source RPM is, as the name indicates, a package of source code used to build architecture-specific packages. Properly labeled source RPMs include the src identifer as part of the file name, like so:

polarbear-2.07-2.src.rpm

Binary RPMs are built from source RPMs. The source RPM contains the source code and specifications necessary to create the binary RPM.

As I continue discussing source RPMs over the next several days, make sure your system includes the rpm-build package, for access to the rpmbuild command.