Friday, 10 October 2014

Expressions used with if condition in shell scripts

1-1. Primary Expressions

PrimaryMeaning
[ -a FILE ]True if FILE exists.
[ -b FILE ]True if FILE exists and is a block-special file.
[ -c FILE ]True if FILE exists and is a character-special file.
[ -d FILE ]True if FILE exists and is a directory.
[ -e FILE ]True if FILE exists.
[ -f FILE ]True if FILE exists and is a regular file.
[ -g FILE ]True if FILE exists and its SGID bit is set.
[ -h FILE ]True if FILE exists and is a symbolic link.
[ -k FILE ]True if FILE exists and its sticky bit is set.
[ -p FILE ]True if FILE exists and is a named pipe (FIFO).
[ -r FILE ]True if FILE exists and is readable.
[ -s FILE ]True if FILE exists and has a size greater than zero.
[ -t FD ]True if file descriptor FD is open and refers to a terminal.
[ -u FILE ]True if FILE exists and its SUID (set user ID) bit is set.
[ -w FILE ]True if FILE exists and is writable.
[ -x FILE ]True if FILE exists and is executable.
[ -O FILE ]True if FILE exists and is owned by the effective user ID.
[ -G FILE ]True if FILE exists and is owned by the effective group ID.
[ -L FILE ]True if FILE exists and is a symbolic link.
[ -N FILE ]True if FILE exists and has been modified since it was last read.
[ -S FILE ]True if FILE exists and is a socket.
[ FILE1 -nt FILE2 ]True if FILE1 has been changed more recently than FILE2, or if FILE1 exists and FILE2 does not.
[ FILE1 -ot FILE2 ]True if FILE1 is older than FILE2, or is FILE2 exists and FILE1 does not.
[ FILE1 -ef FILE2 ]True if FILE1 and FILE2 refer to the same device and inode numbers.
[ -o OPTIONNAME ]True if shell option "OPTIONNAME" is enabled.
[ -z STRING ]True of the length if "STRING" is zero.
[ -n STRING ] or [ STRING ]True if the length of "STRING" is non-zero.
[ STRING1 == STRING2 ] True if the strings are equal. "=" may be used instead of "==" for strict POSIX compliance.
[ STRING1 != STRING2 ] True if the strings are not equal.
[ STRING1 < STRING2 ] True if "STRING1" sorts before "STRING2" lexicographically in the current locale.
[ STRING1 > STRING2 ] True if "STRING1" sorts after "STRING2" lexicographically in the current locale.
[ ARG1 OP ARG2 ]"OP" is one of -eq, -ne, -lt, -le, -gt or -ge. These arithmetic binary operators return true if "ARG1" is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to "ARG2", respectively. "ARG1" and "ARG2" are integers.

Expressions may be combined using the following operators, listed in decreasing order of precedence:

1-2. Combining expressions

OperationEffect
[ ! EXPR ]True if EXPR is false.
[ ( EXPR ) ]Returns the value of EXPR. This may be used to override the normal precedence of operators.
[ EXPR1 -a EXPR2 ]True if both EXPR1 and EXPR2 are true.
[ EXPR1 -o EXPR2 ]True if either EXPR1 or EXPR2 is true.
The [ (or test) built-in evaluates conditional expressions using a set of rules based on the number of arguments. Just like the if is closed with fi, the opening square bracket should be closed after the conditions have been listed.

Monday, 29 September 2014

How to change system hostname in Linux ?

Recently  we got a request from one of our  visitor to post article related to hostname change in Linux operating systems. I am going to cover this  now.

There are two general way to do this 

1)  Temporary 
2)  Permanent

First we go and learn about how to check host name (system name) of the server.
Use "hostname" command to list the system system name.
[root@umser1 ~]# hostname umser1.unixmantra.com [root@umser1 ~]#
    -s, --short              short host name
    -a, --alias               alias names
    -i, --ip-address      addresses for the hostname
    -I, --all-ip-addresses all addresses for the host
    -f, --fqdn, --long    long host name (FQDN)
    -A, --all-fqdns        all long host names (FQDNs)
    -d, --domain           DNS domain name
    -y, --yp, --nis          NIS/YP domainname
    -F, --file                  read hostname or NIS domainname from given fil
In Cent OS  we have another command additionally 
[root@umser1 ~]# sysctl kernel.hostname
kernel.hostname = umser1.unixmantra.com
[root@umser1 ~]#

Change the hostname on a running system (Temporarily) :

This is pretty simple  
#hostname  new-name
will set the hostname of the system to  new-name. This is active right away and will remain like that until the system will be rebooted (because at system boot it will set this from some particular file configurations – see bellow how to set this permanently). You will most probably need to exit the current shell in order to see the change in your shell prompt.

How Do I Change Hostname Permanently?

For Debian  Systems:
Debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh
# /etc/hostname
umser2.unixmantra.com
So on a Debian based system we can edit the file /etc/hostname and change the name of the system and then run:
/etc/init.d/hostname.sh start
to make the change active. The hostname saved in this file (/etc/hostname) will be preserved on system reboot (and will be set using the same script we used hostname.sh).
For Redhat/Fedora/Cent OS Systems:
As you know if you need  changes to be  permanent   you need to hard-code the relevant configuration files.

To make the hostname name permanent in  RH variants ,you must edit the /etc/sysconfig/network file to change  "HOSTNAME" value to your new hostname.
#vi /etc/sysconfig/network

NETWORKING=yes
HOSTNAME="umser2.unixmantra.com"
GATEWAY="192.168.1.1"
GATEWAYDEV="eth0"
FORWARD_IPV4="yes"
Verification:

Open new session and  there you go ,we can  see our  new hostname
[root@umser2 ~]# hostname
umser2.unixmantra.com
[root@umser2 ~]#

Friday, 5 September 2014

Getting "Server refused to allocate pty" upon login attempt

Problem(Abstract)

You are unable to log into AIX because the maximum number of pseudo-terminals have already been allocated.

Symptom

An attempt to log into AIX via telnet or ssh results in this error:

"Server refused to allocate pty"

- You have increased the maximum number of ptys but you still see the problem.
- Each time you log in, the pty number increases and the pty numbers are not getting released and re-used.

Diagnosing the problem

The symptoms may indicate that there is an application that is holding on to ptys and not releasing it.

Try using the 'fuser' command to find the culprit application, like this:
# cd /dev/pts
# fuser *
The 'fuser' command will list all PIDs associated with each pty device.

If there is a process that is not releasing its ptys, you will see its PID occur many times in the fuser output above

Resolving the problem

Restarting the application that you diagnosed above should release all the ptys held by that application. Contact the application vendor support to see if there is a patch or configuration for the problem.

Saturday, 26 July 2014

PowerHA/HACMP Moving Resource Group (RG) one node to other

We are going to discuss about the resource group (RG) movement one node to other in PowerHA.
Here are the steps

1) Extending PATH vairable with cluster paths

Sometimes cluster paths are not included in default path ,run below command incase if you are not able to run commands directly.
export PATH=$PATH:/usr/es/sbin/cluster:/usr/es/sbin/cluster/utilities:/usr/es/sbin/cluster/sbin:/usr/es/sbin/cluster/cspoc

2) Check the cluster services are up  or not in destination node

#clshowsrv -v
Status of the RSCT subsystems used by HACMP:
Subsystem         Group            PID          Status
 topsvcs          topsvcs          278684       active
 grpsvcs          grpsvcs          332026       active
 grpglsm          grpsvcs                       inoperative
 emsvcs           emsvcs           446712       active
 emaixos          emsvcs           294942       active
 ctrmc            rsct             131212       active

Status of the HACMP subsystems:
Subsystem         Group            PID          Status
 clcomdES         clcomdES         204984       active
 clstrmgrES       cluster          86080        active

Status of the optional HACMP subsystems:
Subsystem         Group            PID          Status
 clinfoES         cluster          360702       active

3) Check the availability of resource group

# clRGinfo
-----------------------------------------------------------------------------
Group Name     Type           State      Location
-----------------------------------------------------------------------------
UMRG1            non-concurrent OFFLINE    umhaserv1
                                ONLINE     umhaserv2
#

4) Move the resourcegroup by using below command

==>  clRGmove -g <RG> -n  <node> -m

# clRGmove -g UMRG1 -n umhaserv1 -m
Attempting to move group UMRG1 to node umhaserv1.
Waiting for cluster to process the resource group movement request....
Waiting for the cluster to stabilize..................
Resource group movement successful.
Resource group UMRG1 is online on node umhaserv1.

You can use smitty path also

smitty cl_admin => HACMP Resource Group and Application Management => Move a Resource Group to Another Node / Site

5) Verify the RG movement

# clRGinfo
-----------------------------------------------------------------------------
Group Name     Type           State      Location
-----------------------------------------------------------------------------
UMRG1          non-concurrent   ONLINE     umhaserv1
                                OFFLINE    umhaserv2
#

Thursday, 24 July 2014

Editing the /etc/inittab File in Maintenance Mode

Problem(Abstract)

This technote describes a technique for creating a minimal /etc/inittab file if no other tools are available.

Symptom

System hangs or crashes at boot time.

Cause

A bad entry in the /etc/inittab is keeping the system from booting properly.

Resolving the problem

Ordinarily if there is a problem with one or more entries in the /etc/inittab the preferred method of editing it is:

1. Boot into Maintenance Mode off AIX install CDs, mksysb, or NIM
2. Access the rootvg and start a shell with the filesystems mounted.
3. Edit /etc/inittab down to a minimum 3 lines:
init:2:initdefault:
brc::sysinit:/sbin/rc.boot 3 >/dev/console 2>&1 # Phase 3 of system boot
cons:0123456789:respawn:/usr/sbin/getty /dev/console
In cases where the rootvg filesystems cannot be mounted automatically (for example the CD media is a different Technology Level than what exists on hard disk; or the filesystems for some reason won't automatically mount), commands such as the "vi" editor won't be available to edit the inittab.

In this case a hard-luck method can be used to create a minimal inittab.
1. Boot into Maintenance Mode and choose Option 2 "Access rootvg and start a shell before mounting filesystems".

2. Once in Maintenance Mode, fsck all rootvg filesystems necessary:
# fsck /dev/hd1
# fsck /dev/hd2
# fsck /dev/hd3
# fsck /dev/hd4
# fsck /dev/hd9var

3. Mount root on a temporary mount point:
# mount /dev/hd4 /mnt

4. Copy the bad inittab to a backup:
# cd /mnt/etc
# mv inittab inittab.bad

5. Use grep to create a minimal new inittab:
# grep "init:" inittab.bad > inittab (adds both the init: and brc: entries)
# grep "^cons:" inittab.bad >> inittab (adds the cons: entry)

6. Reboot using the new inittab:
# sync; sync; sync
# cd /
# umount /mnt

power cycle the system from the front panel or HMC

How to enable the Name Service cache Daemon (NSCD)

Question

How do you enable NSCD to improve the performance of the hostname, password, name and group lookup which is frequently being done by IBM Rational ClearCase?

Cause

By enabling the Name Service cache Daemon (NSCD) of the operating system, a significant performance improvement can be achieved when using naming services like DNS, NIS, NIS+, LDAP.

Answer

Benefit of name service cache daemon (NSCD) for ClearCase

Example:

WithoutNSCD:
[user@host]$ time cleartool co -nc "/var/tmp/file"
Checked out "/var/tmp/file" from version "/main/10".
real    0m3.355s
user    0m0.020s
sys     0m0.018s
With NSCD
[user@host]$ time cleartool co -nc "/var/tmp/file"
Checked out "/var/tmp/file" from version "/main/11".
real    0m0.556s
user    0m0.021s
sys     0m0.016s
Enabling NSCD
Solaris:
/etc/init.d/nscd start

Linux
service nscd start

AIX:
startsrc -s netcd
Note: In addition to having nscd started it is mandatory to be sure this service will be started after a reboot. For instance on Red Hat and SuSE you can run:
chkconfig nscd  on
For more details on how to configure and or enable NSCD refer to your respective operating system vendor's manpage.

Note that this service is not yet available on HP-UX platforms.