zcommands: Read gzip Compressed Text Files On a Fly

Posted on in Categories Linux, Tip of the day, UNIX last updated August 31, 2007

Linux and Unix like operating systems comes with z* commands. These commands allow you to read gzip compressed text files using zless, zcat, zmore and friends commands. The gzip command reduces the size of the files using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes, access and modification times. z* commands has some cool usage too; such as display the current time in different zonename.

Domain Expiration Check Shell Script

Posted on in Categories Howto, Shell scripting, Tip of the day, Tips last updated August 21, 2007

I’ve already written about a shell script to check / monitor domain renew / expiration date here. Now I have modified matty’s domain-check script to support additional C/TLDs .in, .biz, .org and .info domains. I’ve also added 5 seconds delay to avoid whois server rejecting query. This script checks to see if a domain has expired. It can be run in interactive and batch mode, and provides facilities to alarm if a domain is about to expire in advance.

Sample usage

Display expiration date and registrar for theos.in domain:
$domain-check-2 -d {domain-name}
$ domain-check-2 -d theos.in

Sample outputs:

Domain                              Registrar         Status   Expires     Days Left
----------------------------------- ----------------- -------- ----------- ---------
theos.in                            et4India (R7-AFIN Valid    28-Oct-2009   799  

You can also get an email if theos.in going to expire in 30 days
$ domain-check-2 -a -d theos.in -q -x 30 -e [email protected]

However most killer feature is you can read list of domain names from a file such as mydomains.txt (list each domain on a new line):
$ domain-check-2 -a -f mydomains.txt -q -x 30 -e [email protected]
OR
$ domain-check-2 -f mydomains.txt

Output:

Domain                              Registrar         Status   Expires     Days Left
----------------------------------- ----------------- -------- ----------- ---------
theos.in                            et4India (R7-AFIN Valid    28-Oct-2009   799
nixcraft.org                        oDaddy.com, Inc.  Valid    13-Aug-2009   723
vivekgite.com                       MONIKER ONLINE SE Valid    18-aug-2010   1093
cyberciti.biz                                         Valid    30-Jun-2009   679
nixcraft.info                       oDaddy.com Inc. ( Valid    26-Jun-2009   675
nixcraft.net                        GODADDY.COM, INC. Valid    11-dec-2009   843  

Download

=> You can download modified domain-check-2 script here and an updated version is here too.

Quick installation

Use wget command to download and install domain-check script:
$ wget http://www.cyberciti.biz/files/scripts/domain-check-2.txt
$ mv domain-check-2.txt domain-check
$ chmod +x domain-check
$ ./domain-check -d vivekgite.com

Make sure your run domain-check script using a cron job.

Ubuntu Linux install development / system library functions man pages (manual)

Posted on in Categories Debian Linux, Tip of the day, Troubleshooting, Ubuntu Linux last updated July 30, 2007

I am little surprised to find that Ubuntu Linux skips development man pages by default on cloud-based images. A quick search using apt-cache pointed out that I need to install the manpages-dev package on a Ubuntu Linux. It includes manual pages about using GNU/Linux for development. The manpages-posix-dev package includes manual pages about using a POSIX system for development. The man-db package is the on-line manual page i.e. actual man command to view man pages on a Ubuntu or Debian Linux.

Install development man pages on Ubuntu/Debian Linux

Type the following apt-get command to install various packages to view man pages for C standard library functions in Ubuntu or Debian system:
$ sudo apt-get install manpages-dev man-db manpages-posix-dev
Sample outputs:

Fig.01: Installing man pages on a Ubuntu or Debian Linux system
Fig.01: Installing man pages on a Ubuntu or Debian Linux system

How do I view man pages?

To view library calls (functions within program libraries), enter:
$ man 3 function-name
$ man 3 putc
$ man 3 strlen
$ man 3 printf
$ man 3 scanf
$ man 2 execve
$ man 2 fork

The number 3 or 2 indicates the section numbers of the manual as follows:

  • 2 : System calls (functions provided by the kernel)
  • 3 : Library calls (functions within program libraries)

See man page sections for more info:
$ man man

See also

Howto: Verify Downloaded Linux / BSD DVD or CD ISO images for integrity

Posted on in Categories CentOS, Debian Linux, Howto, Linux, Linux distribution, RedHat/Fedora Linux, Security, Sys admin, Tip of the day, Ubuntu Linux, UNIX last updated July 26, 2007

You need to verify that that downloaded Linux DVD or ISO images are intact before you burn and use them. This is security feature. But how do you verify ISO images?

Answer is quite simple use md5sum command to compute and check MD5 message digest.

Why verify ISO images?

a) To protect yourself
b) Verify that a file has not changed as a result of file transfer, disk error, cracker attacks, etc.

How does it work?

When you run md5sum command on ISO file, you get checksum (or hash) on screen. You need to compare this checksum with original. It works as a compact digital fingerprint of a file. You can then compare the MD5 hash of your download ISO file, to the known good hash of the file you are checking. If the two values match, you are safe and use the ISO image.

Example

Let us download FreeBSD ISO image:
$ cd /tmp
$ wget ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/6.2/6.2-RELEASE-i386-bootonly.iso

Next download MD5 checksum:
$ wget ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/6.2/CHECKSUM.MD5

Generate MD5 hash for ISO image

$ md5sum 6.2-RELEASE-i386-bootonly.iso
Output:

4e8701ac951bc4537f8420fdac7efbb5  6.2-RELEASE-i386-bootonly.iso

Verify ISO image

See the known good hash of the file (6.2-RELEASE-i386-bootonly.iso):
$ md5sum -c CHECKSUM.MD5
Output:

6.2-RELEASE-i386-bootonly.iso: OK

You can also use following command for the same purpose:

A note for Windows XP / Vista users

Fix corrupted RPM database on CentOS 5 / Redhat enterprise Linux 5 / Fedora 7

Posted on in Categories CentOS, Linux, Linux distribution, RedHat/Fedora Linux, Tip of the day last updated July 25, 2007

If rpm / yum command hangs during operations or you see error messages – it means your rpm database corrupted. /var/lib/rpm/ stores rpm database just delete the same and rebuild rpm database:

Command to rebuild rpm database

rm -f /var/lib/rpm/__db*
rpm --rebuilddb

Read rpm / yum man pages for more information

Repeat last shell command that started with a particular word

Posted on in Categories Shell scripting, Tip of the day, Tips, UNIX last updated July 8, 2007

Bash / CSH shell offers command history feature. Most of you may be aware and using of UP / DOWN arrow keys to recall previous commands. History expansions introduce words from the history list into the input stream, making it easy to repeat commands, insert the arguments to a previous ommand into the current input line, or fix errors in previous commands quickly.

To repeat last command that started with bar word type i.e. refer to the most recent command starting with string bar):
! bar

For example, let us run lighttpd to test config file:
# /usr/sbin/lighttpd -t -f /jail/usr/local/etc/lighttpd/lighttpd.conf
Output:

Syntax OK

Type few commands:
# pwd
# date

Now to repeat last command that started with lighttpd word type
# !lighttpd
Output:

lighttpd -t -f /jail/usr/local/etc/lighttpd/lighttpd.conf
Syntax OK 

Want to refer to the previous command, just enter
!!

Related shell tip

Troubleshooting tip: Lan card (NIC) ordering changed after upgrading to Redhat (RHEL) Linux 4.5

Posted on in Categories CentOS, Linux, Linux distribution, RedHat/Fedora Linux, Sys admin, Tip of the day, Troubleshooting last updated June 15, 2007

If you are running Dell PowerEdge 2950 server or HP ProLiant BL480c G1 server and upgraded from old version to latest Red Hat Enterprise Linux ES release 4.5 (Nahant Update 5) you will notice that ordering of your NIC devices changed.

Fix problem before upgrade:

Before running upgrade via up2date command open /etc/sysconfig/network-scripts/ifcfg-eth0 file (for NIC 0) and add line
HWADDR=My-MAC-ADDRESS

Now proceed to upgrade using up2date -u
# up2date -u

Howto fix problem after upgrade:

However chances are very high that after running up2date -u command (i.e. after upgrade) you may notice the problem. Don’t panic. Open grub.conf file:
# vi /etc/grub.conf

Find out current kernel line:
kernel /vmlinuz-2.6.9-55.ELsmp ro root=LABEL=/ console=tty0 console=ttyS1,19200n8

Replace as follows:
kernel /vmlinuz-2.6.9-55.ELsmp ro root=LABEL=/ console=tty0 console=ttyS1,19200n8 pci=nobfsort

The pci=nobfsort option restore the original Kernel 2.6 ordering.

A final note

This problem is not Redhat specific. It can occurred on Suse or any other Linux distribution. Please see Linux enumeration of NICs solution published by Dell for more information.

Howto: Prevent a Linux kernel module from auto loading

Posted on in Categories CentOS, Debian Linux, Howto, Linux, RedHat/Fedora Linux, Sys admin, Tip of the day, Troubleshooting last updated June 13, 2007

In some situation you may want to avoid loading a Linux driver module automatically . For example:
[a] You would like to use proprietary device driver (I’m against any sort of proprietary drivers) and not inbuilt (reverse engineer) kernel driver.

[b] If your server system connected without a diskette / floppy drive; kernel will try to load floppy driver – disable floppy driver or module.

[c] In some cases buggy driver causes kernel BUG on load so you just want to avoid the problem.

The Linux kernel get module information from /etc/modprobe.conf file and /etc/modprobe.d/* file(s).

If you are using CentOS/Redhat/RHEL/Fedora Linux…

Just open your /etc/modprobe.conf file and turn of auto loading using following syntax:
alias driver-name off

If you are using Debian / Ubuntu Linux…

open /etc/modprobe.d/blacklist file and add drivername using following syntax:
blacklist driver-name

Reboot your box and use lsmod command to show the status of modules in the Linux Kernel.

Shell tip: change to a directory having very long name

Posted on in Categories Howto, Linux, Shell scripting, Tip of the day, Tips, UNIX last updated June 6, 2007

Let us say your have a long directory name called “A_VERY_ VERY LONG_ DIRECTORY_NAME_TO_ TYPE _ A _ B _C”…

So how do you change to a directory, which is having very long name without typing full name?

Simply use a wildcard character called * as follows
$ cd A_VERY_VERY*

Or type cd A_VERY and hit tab key to complete a directory name 🙂
$ cd A_VERY_VERY (hit tab key)

Linux turn OFF password expiration / aging

Posted on in Categories Debian Linux, Howto, Linux, RedHat/Fedora Linux, Security, Suse Linux, Sys admin, Tip of the day, Tips, Troubleshooting, Ubuntu Linux last updated May 22, 2007

/etc/shadow stores actual password in encrypted format for user’s account with additional properties related to user password.

The password expiration information for a user is contained in the last 6 fields. Password expiration for a select user can be disabled by editing the /etc/shadow file

However I recommend using chage command. The chage command changes the number of days between password changes and the date of the last password change. This information is used by the system to determine when a user must change his/her password.

To list current aging type chage command as follows:
# chage -l vivek
Output:

Last password change                                    : May 22, 2007
Password expires                                        : never
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 0
Maximum number of days between password change          : 99999
Number of days of warning before password expires       : 7

To disable password aging / expiration for user foo, type command as follows and set:
Minimum Password Age to 0
Maximum Password Age to 99999
Password Inactive to -1
Account Expiration Date to -1
Interactive mode command:
# chage username
OR
# chage -I -1 -m 0 -M 99999 -E -1 username

Updated for accuracy.