Wednesday, 28 August 2013

Printf examples

awk -F: '{ printf("%-15s %s\n", $1, $5) }' /etc/passwd
printf "%-21s %-s\n", "--from", "search envelope sender address";
printf "%-9s %-16s %-8s %-8s\n" "Switch" "MAC address" "Module" "Port" > $OUTPUT_FILE

vi temporary work file location

By default, vi places temporary work files in /var/tmp. You may want to redirect these work files to another location, especially if /var cannot be mounted in case of an error in your system's file system table (e.g. /etc/vfstab, /etc/fstab).

A temporary way to redirect these files:
EXINIT="set dir=directory" vi file

e.g. EXINIT="set dir=/tmp" vi /etc/vfstab

To set this permanently for a user, add the command to the user's ~/.exrc initialization file.
echo "set dir=directory" >> ~/.exrc

e.g. echo "set dir=/tmp" >> ~/.exrc

For more information, read the ex man page.

Solaris-Changing IP address

The following steps may be used to change the IP address of a Solaris system.

1. Change the host's IP in /etc/hosts for the change to take effect after reboot. If you are using Solaris 10, you must also change the host's IP in /etc/inet/ipnodes for the change to take effect after reboot.

2. Run ifconfig interface ip_address netmask broadcast_address for the IP address change to take effect immediately. The netmask and broadcast_address should be specified if you are using variable length subnet masks (VLSM), but may be omitted otherwise.

3. If you are using variable length subnet masks (VLSM), add the host's network number and subnet mask to /etc/netmasks.
If the new IP address places the system on a different network:

4. Place the host's new default gateway in /etc/defaultrouter

5. Run route add default new_gateway for the new default gateway to take effect immediately.

6. Run route delete default old_gateway to delete the old default gateway from the routing table

AIX Error logging

This procedure provides the steps that are required to check the AIX error log.
After the terminal window is open, simply type
errpt |pg (pg permits you to display one page at a time)
The columns that you need to review are:
(Column #2)
Provides a shortcut version of the date and time.
0827 = August 27th
0415 = 4:15 AM OR 04:15 hours
13 = the year, 2013

(Column #3)
Displays the type code for the error:
I = Informational
P = Permanent
T = Temporary
Warning:  If a type code of P (Permanent) appears, contact the appropriate AIX Support.

(Column #4)
Displays a descriptor of the environment in which the error has occurred.
The codes are:
H = Hardware
S = Software
O = Operating Environment

Few Example Command

To display a complete summary report, enter:

To display a complete detailed report, enter: 
errpt -a

To display a detailed report of all errors logged for the error identifier E19E094F, enter: 
errpt -a -j E19E094F

To list error-record templates for which logging is turned off for any error-log entries, enter: 
errpt -t -F log=0

To view all entries from the alternate error-log file /var/adm/ras/errlog.alternate, enter: 
errpt -i /var/adm/ras/errlog.alternate

To view all hardware entries from the error-log file enter: 
errpt -d H

To view all software entries from the error-log file enter:
errpt -d S

To display a detailed report of all errors logged for the error label ERRLOG_ON, enter: 
errpt -a -J ERRLOG_ON

To display a detailed report of all errors and group duplicate errors, enter:
errpt -aD

To display the error-record template repository, enter:
errpt -t

To disable the reporting of the ERRLOG_OFF event (error ID 192AC071), type the following:
errupdate <Enter>
=192AC071: <Enter>
Report=False <Enter>

To enable the reporting of the ERRLOG_OFF event (error ID 192AC071) in case it was turned off, type the following:
errupdate <Enter>
=192AC071: <Enter>
Report=True <Enter>

To delete the ERRLOG_OFF event (error ID 192AC071) from the Error Record Template Repository, type the following:
errupdate <Enter>

To disable the logging of the ERRLOG_OFF event (error ID 192AC071), type the following:
errupdate <Enter>
=192AC071: <Enter>
Log=False <Enter>

To delete all entries from the error log, enter:
errclear 0

To delete all entries from the error log older than 3 days, enter:
errclear 3

To create an operator message for system drive reconfiguration, enter:
errlogger system drive reconfigured

To delete all entries in the error log classified as software errors, enter:
errclear -d S 0

To clear all entries from the alternate error-log file /var/adm/ras/errlog.alternate, enter:
errclear -i /var/adm/ras/errlog.alternate 0

Tuesday, 27 August 2013

Howto Red Hat Enterprise Linux configuring the network

Red hat Linux provides following tools to make changes to Network configuration such as add new card, assign IP address, change DNS server, etcetera:

  • GUI tool (X windows required) - system-config-network
  • Command line text based GUI tool (No X windows required) - system-config-network-tui
  • Edit configuration files directly, stored in /etc/sysconfig/network-scripts directory
The following instructions are compatible with CentOS, Fedora Core and Red Hat Enterprise Linux 3, 4 and 5.
Editing the configuration files stored in /etc/sysconfig/network-scripts:
First change directory to /etc/sysconfig/network-scripts/:
# cd /etc/sysconfig/network-scripts/
You need to edit / create files as follows:
  • /etc/sysconfig/network-scripts/ifcfg-eth0 : First Ethernet card configuration file
  • /etc/sysconfig/network-scripts/ifcfg-eth1 : Second Ethernet card configuration file
To edit/create the first NIC file, type the following command:
# vi ifcfg-eth0
Append/modify as follows:
# Intel Corporation 82573E Gigabit Ethernet Controller (Copper)
Save and close the file. Define the default gateway (router IP) and hostname in /etc/sysconfig/network file:
# vi /etc/sysconfig/network
Save and close the file. Restart networking:
# /etc/init.d/network restart
Make sure you have correct DNS server defined in /etc/resolv.conf file. Try to ping the gateway, and other hosts on your network. Also check if you can resolv host names:
# nslookup
And verify if the NTP servers are correct in /etc/ntp.conf, and if you can connect to the time server, by running the ntpdate command against one of the NTP servers:
# ntpdate
This should synchronize system time with time server

Monday, 26 August 2013

List of Important files and Directories in Linux (Redhat,Centos,Fedora)

In this section we are going to learn about the important files and directories in the Linux OS like Redhat,Centos,Fedora).

you will get good idea  to clear about yourself.

Hidden “Dot” Files

There are some files within the home directory that are ordinarily hidden.  Hidden files have names that begin with a period; hence, they have been given the nickname of dot files.  Hidden files are not displayed by the ls command unless the –a option is used in the format of ls –a.

Table 1 below lists some of the more common dot files that users should know about.  This is by no means a totally comprehensive list.  Additional dot files can be found in the user’s home directory; however, some searches may not find some of the files listed here.  The files found are dependent upon the applications installed on the server, the utilities that are in use and the command shell that is being used.  Since the default shell for Linux is the bash shell, the home directory contains the bash related scripts indicated below.

File Description

For users of the bash shell, a file containing up to 500 of the most recent commands available for recall using the up and down arrow keys.
Script that is run by the bash shell when the user logs out of the system
Initialization script that is run by the bash shell upon login in order to setup variables and aliases.  When bash is started as the default login shell, it looks for the .bash_profile file in the user’s home directory; if not found, it looks for .bash_login.  If there is no .bash_login file, it then looks for a .profile file.
Initialization script executed whenever the bash shell is started in some way other than a login shell. It is better to put system-wide functions and aliases in /etc/bashrc, which will be presented later in the book.
GTK initialization file.  GTK+ is a multi-platform toolkit for creating graphical user interfaces, used by a large number of applications.  It is the toolkit used by the GNU project's GNOME desktop.
The initialization script that is run whenever a user login occurs.
The script that is automatically run whenever a user logout occurs.
Put default system-wide environment variables in /etc/profile.
Initialization file for the Vim text editor that is compatible with vi.
Specifys the default window manager if one is not specified in startx
.Xdefaults & .Xresources
Initialization files for Xterm resources for the user. Application program behavior can be changed by modifying these files.
The initialization file used when running startx, which can be used to activate applications and run a particular window manager.
This file is executed when a user logs in to an X-terminal and is used to automatically load the window manager and applications.
Table 1: Common dot files for the bash shell

When these files do not exist in the user’s home directory, programs that use the files will often use a global default configuration file installed in one of the subdirectories in which the package is installed.
The list below indicates the dot files installed in tclark’s home directory.

-rw-------    1 roseat   roseat        3773 Jan 13 21:39 .bash_history
-rw-r--r--    1 roseat   roseat        24 Aug 18 11:23 .bash_logout
-rw-r--r--    1 roseat   roseat        191 Aug 18 11:23 .bash_profile
-rw-r--r--    1 roseat   roseat        124 Aug 18 11:23 .bashrc
-rw-r--r--    1 roseat   roseat        237 May 22  2003 .emacs
-rw-r--r--    1 roseat   roseat        120 Aug 24 06:44 .gtkrc
The following is the content of the .bash_logout file in tclark’s home directory, which is executed whenever logging out of the system.  It does nothing more than clear the screen upon logout.

# ~/.bash_logout
The following is the content of the .bashrc file from tclark’s home directory.  Shell scripts will be presented in a later chapter, but for now suffice it to say that the script looks for a file in the /etc directory called bashrc and execute it if the file exists.

# .bashrc
# User specific aliases and functions
# Source global definitions

if [ -f /etc/bashrc ]; then
        . /etc/bashrc
These files primarily affect individual users on the Linux system.  Next we'll look at the files which affect the entire system.

Important System Files

Everything in the Linux environment exists in files.  It makes sense for users to become familiar with some of the more important Linux system files.  Some of these are configuration files, others are devices which Linux makes available through files and some are executable programs.

Table 2 below is by no means intended to be an exhaustive list of Linux system files; however, it is a good representation to give some insight into the inner workings of Linux.

The Linux kernel file.  File naming conventions may include release information
Device file for the first floppy disk drive on the system
Device driver for the first floppy drive in high density mode, commonly invoked when formatting a floppy diskette for that density
Device file for the first IDE hard drive on the system
Commonly, the IDE CDROM drive device file which often is a symbolic link called to /dev/cdrom, the real CDROM driver file.
A dummy device which contains nothing.  It is sometimes useful to send output to this device to make it go away forever.
Contains aliases used by sendmail and other mail transport agents. Whenever this file is changed, the newaliases utility must be run to notify sendmail of the changes
Contains global defaults and aliases used by the bash shell
A parent shell script to run commands periodically.  It invokes hourly, daily, weekly, and monthly scripts.
Contains a list of filesystems which may be made available to other systems on the network via NFS.
The file system table contains the description of what disk devices are available at what mount points.
Holds information regarding security group definitions.
The grub boot loader configuration file
Contains host names and their corresponding IP addresses used for name resolution whenever a DNS server is unavailable
Contains a list of hosts allowed to access services on this computer.
Contains a list of hosts forbidden to access services on this computer.
Describes how the INIT process should set up the system in various runlevels
Contains the pre-login message, often overwritten by the /etc/rc.d/rc.local script in Red Hat and some other rpm-based Linux distributions
The lilo boot loader configuration file
Holds options for configurable system modules
This is the ”message of the day” file which is printed upon login. It can be overwritten by /etc/rc.d/rc.local Red Hat on startup.
Status information for currently mounted devices and partitions
Contains information regarding registered system users. Passwords are typically kept in a shadow file for better security.
Holds printer setup information
Contains global defaults for the bash shell
A list of domain name servers (DNS) used by the local machine
This file contains a list of terminals where root can login
An extensive ASCII text file defining the properties of consoles, terminals, and printers
Contains CPU related information
Holds information regarding filesystems that are currently in use
Stores the interrupts that are currently being used
A list of the I/O addresses used by devices connected to the server
Contains memory usage information for both physical memory and swap
Lists currently loaded kernel modules
Displays currently mounted file systems
Contains various statistics about the system, such as the number of page faults since the system was last booted
Holds swap file utilization information
Contains Linux version information
Stores information about the last boot process
Contains messages produced by the syslog daemon during the boot process
A binary data file holding login time and duration for each user currently on the system

Table 2: Representative list of Linux files

Now let's look at the contents of some files from tclark’s server.  Since these files contain variable information, do not expect the files on every server to look exactly like these.

The following is part of the file /etc/passwd.  The second field has an x as a placeholder for the password.  This indicates that the passwords for each user are being kept in a shadow file.

# cat /etc/passwd
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
oracle:x:500:501:Oracle Software Owner:/home/oracle:/bin/bash
roseat:x:503:504:Rose Seat:/home/roseat:/bin/bash

The fields in this file are separated by colons.  In order the fields are username, password (or placeholder), user ID number, primary group ID number, user's full name, user's home directory and user's default shell.

The file system table, /etc/fstab, defines parameters for mounting partitions and devices as filesystems.  The fields displayed below indicated the device or filesystem to be mounted, the mount point, the type of filesystem, the mount options, dump option, and file check order at boot time.

# cat /etc/fstab
/dev/md0                /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
LABEL=/bootback         /bootback               ext3    defaults        1 2
none                    /dev/pts                devpts  gid=5,mode=620  0 0

none                    /proc                   proc    defaults        0 0

none                    /dev/shm                tmpfs   defaults        0 0

/dev/hdd1               swap                    swap    defaults        0 0

/dev/hdc1               swap                    swap    defaults        0 0
/dev/hdb3               swap                    swap    defaults        0 0
/dev/cdrom              /mnt/cdrom              udf,iso9660 noauto,owner,kudzu,ro 0 0
/dev/fd0                /mnt/floppy             auto    noauto,owner,kudzu 0 0

The /proc/meminfo file contains real and virtual memory usage statistics.
# cat /proc/meminfo
Mem:  2107744256 2088869888 18874368        0 180436992 1587232768
Swap: 1508102144 13074432 1495027712
MemTotal:      2058344 kB
MemFree:         18432 kB
MemShared:           0 kB
Buffers:        176208 kB
Cached:        1544780 kB
SwapCached:       5252 kB
Active:        1391876 kB
ActiveAnon:     790712 kB
ActiveCache:    601164 kB
Inact_dirty:    437124 kB
Inact_laundry:   90216 kB
Inact_clean:     41596 kB
Inact_target:   392160 kB
HighTotal:     1179328 kB
HighFree:         5588 kB
LowTotal:       879016 kB
LowFree:         12844 kB
SwapTotal:     1472756 kB
SwapFree:      1459988 kB
Committed_AS:  1565668 kB
HugePages_Total:     0
HugePages_Free:      0
Hugepagesize:     4096 kB
Next we'll look at some of the significant directories on the Linux system.  Some of these will be familiar as the location of the files we've just looked at.

Important Directories

Although organizations have made strides toward consistency via standards such as the Linux Filesystem Hierarchy Standard (FHS), different Linux distributions still have somewhat different directory structures.  The following rendering exemplifies a typical Red Hat effort toward standardization of where files are stored according to type and use.

All binaries needed for the boot process and to run the system in single-user mode, including essential commands such as cd, ls, etc.
Holds files used during the boot process along with the Linux kernel itself
Contains device files for all hardware devices on the system
Files used by application subsystems such as mail, the Oracle database, etc.
Contains various service startup scripts
Holds application setup scripts run by /etc/profile upon login
Contains subdirectories which contain run level specific scripts
run level initialization scripts
Where ‘?’ is a number corresponding to the default run level. Contains symbolic links to scripts which are in /etc/rc.d/init.d. for services to be started and stopped at the indicated run level.
Holds example dot files used to populate a new user's home directory.
Contains subdirectories and configuration files for the X Window system
User home directories
Some shared library directories, files, and links
The typical mount point for the user-mountable devices such as floppy drives and CDROM
Virtual file system that provides system statistics.  It doesn't contain real files but provides an interface to runtime system information.
Home directory for the root user
Commands used by the super user for system administrative functions
A standard repository for temporary files created by applications and users.
Directory contains subdirectories with source code, programs, libraries, documentation, etc.
Contains commands available to normal users
X Window system  binaries
Holds include files used in C programs
Contains shared directories for man files, info files, etc.
Library files searched by the linker when programs are compiled
Common executable application files local to this system
Commands used by the super user for system administrative functions
Administrative files such as log files, locks, spool files, and temporary files used by various utilities

The contents of these directories will vary from system to system but most of these directories will typically be present.  Often when you install software or a new device on a Linux system files will be added or modified in these directories to make everything work.