Wednesday 28 August 2013

Printf examples

awk
awk -F: '{ printf("%-15s %s\n", $1, $5) }' /etc/passwd
perl
printf "%-21s %-s\n", "--from", "search envelope sender address";
shell
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:
TIMESTAMP
(Column #2)
Provides a shortcut version of the date and time.
Example:0827041513
0827 = August 27th
0415 = 4:15 AM OR 04:15 hours
13 = the year, 2013


T
(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.


C
(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:
errpt

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>
<Ctrl-D>
<Ctrl-D>

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>
<Ctrl-D>
<Ctrl-D>

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

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

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)
DEVICE=eth0
BOOTPROTO=static
DHCPCLASS=
HWADDR=00:30:48:56:A6:2E
IPADDR=10.6.55.114
NETMASK=255.255.255.0
ONBOOT=yes
Save and close the file. Define the default gateway (router IP) and hostname in /etc/sysconfig/network file:
# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=host.domain.com
GATEWAY=10.6.55.1
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 host.domain.com
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 10.20.30.40
This should synchronize system time with time server 10.20.30.40.

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


File
Description
.bash_history
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.
.bash_logout
Script that is run by the bash shell when the user logs out of the system
.bash_profile
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.
.bashrc
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.
.gtkrc
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.
.login
The initialization script that is run whenever a user login occurs.
.logout
The script that is automatically run whenever a user logout occurs.
.profile
Put default system-wide environment variables in /etc/profile.
.viminfo
Initialization file for the Vim text editor that is compatible with vi.
.wm_style
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.
.xinitrc
The initialization file used when running startx, which can be used to activate applications and run a particular window manager.
.xsession
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
clear
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
fi
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.

File
Description
/boot/vmlinuz
The Linux kernel file.  File naming conventions may include release information
/dev/fd0
Device file for the first floppy disk drive on the system
/dev/fd0H1440
Device driver for the first floppy drive in high density mode, commonly invoked when formatting a floppy diskette for that density
/dev/hda
Device file for the first IDE hard drive on the system
/dev/hdc
Commonly, the IDE CDROM drive device file which often is a symbolic link called to /dev/cdrom, the real CDROM driver file.
/dev/null
A dummy device which contains nothing.  It is sometimes useful to send output to this device to make it go away forever.
/etc/aliases
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
/etc/bashrc
Contains global defaults and aliases used by the bash shell
/etc/crontab
A parent shell script to run commands periodically.  It invokes hourly, daily, weekly, and monthly scripts.
/etc/exports
Contains a list of filesystems which may be made available to other systems on the network via NFS.
/etc/fstab
The file system table contains the description of what disk devices are available at what mount points.
/etc/group
Holds information regarding security group definitions.
/etc/grub.conf
The grub boot loader configuration file
/etc/hosts
Contains host names and their corresponding IP addresses used for name resolution whenever a DNS server is unavailable
/etc/hosts.allow
Contains a list of hosts allowed to access services on this computer.
/etc/hosts.deny
Contains a list of hosts forbidden to access services on this computer.
/etc/inittab
Describes how the INIT process should set up the system in various runlevels
/etc/issue
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
/etc/lilo.conf
The lilo boot loader configuration file
/etc/modules.conf
Holds options for configurable system modules
/etc/motd
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.
/etc/mtab
Status information for currently mounted devices and partitions
/etc/passwd
Contains information regarding registered system users. Passwords are typically kept in a shadow file for better security.
/etc/printcap
Holds printer setup information
/etc/profile
Contains global defaults for the bash shell
/etc/resolv.conf
A list of domain name servers (DNS) used by the local machine
/etc/securetty
This file contains a list of terminals where root can login
/etc/termcap
An extensive ASCII text file defining the properties of consoles, terminals, and printers
/proc/cpuinfo
Contains CPU related information
/proc/filesystems
Holds information regarding filesystems that are currently in use
/proc/interrupts
Stores the interrupts that are currently being used
/proc/ioports
A list of the I/O addresses used by devices connected to the server
/proc/meminfo
Contains memory usage information for both physical memory and swap
/proc/modules
Lists currently loaded kernel modules
/proc/mounts 
Displays currently mounted file systems
/proc/stat
Contains various statistics about the system, such as the number of page faults since the system was last booted
/proc/swaps
Holds swap file utilization information
/proc/version
Contains Linux version information
/var/log/lastlog
Stores information about the last boot process
/var/log/messages
Contains messages produced by the syslog daemon during the boot process
/var/log/wtmp
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.

/etc/passwd:
# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
rpm:x:37:37::/var/lib/rpm:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
apache:x:48:48:Apache:/var/www:/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.

/etc/fstab: 
# 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.
/proc/meminfo:
# 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.

Directory
Description
/bin
All binaries needed for the boot process and to run the system in single-user mode, including essential commands such as cd, ls, etc.
/boot
Holds files used during the boot process along with the Linux kernel itself
/dev
Contains device files for all hardware devices on the system
/etc
Files used by application subsystems such as mail, the Oracle database, etc.
/etc/init.d
Contains various service startup scripts
/etc/profile.d
Holds application setup scripts run by /etc/profile upon login
/etc/rc.d
Contains subdirectories which contain run level specific scripts
/etc/rc.d/init.d
run level initialization scripts
/etc/rc.d/rc?.d
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.
/etc/skel
Holds example dot files used to populate a new user's home directory.
/etc/X11
Contains subdirectories and configuration files for the X Window system
/home
User home directories
/lib
Some shared library directories, files, and links
/mnt
The typical mount point for the user-mountable devices such as floppy drives and CDROM
/proc
Virtual file system that provides system statistics.  It doesn't contain real files but provides an interface to runtime system information.
/root
Home directory for the root user
/sbin
Commands used by the super user for system administrative functions
/tmp
A standard repository for temporary files created by applications and users.
/usr
Directory contains subdirectories with source code, programs, libraries, documentation, etc.
/usr/bin
Contains commands available to normal users
/usr/bin/X11
X Window system  binaries
/usr/include
Holds include files used in C programs
/usr/share
Contains shared directories for man files, info files, etc.
/usr/lib
Library files searched by the linker when programs are compiled
/usr/local/bin
Common executable application files local to this system
/usr/sbin
Commands used by the super user for system administrative functions
/var
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.