Thursday 18 December 2014

Tar Files extraction Unix / Linux

Q: How can I extract  specific file from a tar ball ?

Tar or Tar ball is a single file  bundled with files &/ directories. First  we will discuss about general extraction of a files from tar ball.

Unpack or extract a tar file :

To unpack or extract a tar file, type:
tar -xvf myfile.tar
some times to save more space and bandwidth , we  need compress the tar balls using compression techniques like gzip or bzip2.

To unzip and extract  those tar files, type as below 
For  .tar.gz files 
tar -xzvf myfile.tar.gz

For .tar.bz2
tar -xjvf myfile.tar.bz2
Where,
-x : Extract a tar ball.
-v : Verbose output or show progress while extracting files.
-f : Specify an archive or a tarball filename.
-j : Decompress and extract the contents of the compressed archive created by bzip2 program (tar.bz2 extension).
-z : Decompress and extract the contents of the compressed archive created by gzip program (tar.gz extension).
Now here comes our main purpose ,  to extract a specific file  from a tar file.

Extract Specific file from a tar ball:

To extract a single file called myfile1.txt, enter:
tar -xvf file.tar myfile1.txt
tar -xzvf file.tar.gz myfile1.txt
tar -xjvf file.tar.bz2 myfile1.txt
You can also specify path such as home/um/myfile2.txt, enter:
tar -xvf file.tar home/um/myfile2.txt
tar -xzvf file.tar.gz home/um/myfile2.txt
tar -xjvf file.tar.bz2 home/um/myfile2.txt

How to Extract a Single Directory?

To extract a single directory called /home/um, enter:
tar -xvf file.tar home/um
tar -xzvf file.tar.gz home/um
tar -xjvf file.tar.bz2 home/um

Sample O/P:
home/um/
home/um/ddl/
home/um/ddl/default
home/um/ddl/bin/config.conf
home/um/ddl/daemon.conf
home/um/ddl/config/system.sh

Wednesday 17 December 2014

MobaXterm free Xserver and SSH client

Recently when I am browsing internet  for Unix connectivity tools I came across a wonderful tool called MobaXterm. As per the MobaXterm team  its "an enhanced terminal for Windows with an X11 server, a tabbed SSH client and several other network tools for remote computing (VNC, RDP, telnet, rlogin). MobaXterm brings all the essential UNIX commands to Windows desktop, in a single portable exe file which works out of the box".

Downaload:There are two different versions available, one is free version and other is Pro.
I think free version is good enough to accommodate our daily tasks. If you still  feel you need  more then  go for Pro.

Download Link

The following are  the key features mentioned by them.

Key Features:
  • Free X server fully configured (based on Xorg)
  • Tabbed terminal based on PuTTY / MinTTY with antialiased fonts and macro support
  • Easy DISPLAY exportation from any remote host
  • X11-Forwarding capability in OpenSSH
  • Several Unix/Linux commands based on Cygwin (rsync, wget, sed, awk, grep, cd, ls, cat, cp, ...)
  • A session manager with all the network clients you need: RDP, VNC, SSH, telnet, rsh, FTP, SFTP and XDMCP
  • Program without installation that you can start from an USB stick
  • Light and portable application, packaged in a single executable


I am really enthralled by the features its offering.Here are few snippets.

1) Inbuilt Unix Command Support :
When you open MobaXterm  it will automatically  open session which supports many of Unix/Linux based commands  (ls, cd, grep, awk, tail, cut, sed, wget, rsync, telnet, ssh, rlogin, rsh etc ) based on Cygwin. You can further add packages using this link plugins.

2)Tabbed Sessions:
When ever you open a session , it will be open as tabbed session, just like Putty Connection Manager.
You can also save your session along with usernames and passwords

3)X11-Forwarding
The SSH connection configured with automatic X-11 forwarding.You can use this as fully configured "X server " and also supports OpenGL.

4) Automatic SFTP Support:
A SFTP session is automatically opened when you open a ssh session on leftside. You can  download or upload files directly with a drag and drop from/to the remote server.You  can also  edit And save the files with one click open it in MobiXeditor or  which ever the text editor on your system.

5) Remote Windows Connections using RDP: 
  You can access the remote windows machines using RDP adding as connection.

6) Split-mode Terminal:
you can display up to 4 terminals at the same time in the main window. It is very useful for monitoring 4 remote computers or for comparing outputs of 2 terminals.

7) Multiple Sessions Support:
It will support various session types like SSH,RSH,Telnet,Xdmcp,RDP,VNC, SFTP,FTP many more.

8) Muti Execution Mode:
There us a facility just klike PuttyCM, You can run one single command in all the open sessions.But be more cautious when you are using this facility, need to be careful on which sessions you are running this.

---
There are lot more features and further information you can refer the following link.
more features link

Saturday 15 November 2014

Manually Installing PHP in Linux

Before installing php,  we need to install apache.The most recent version of Apache HTTP Server may be obtained from >> Apache Download.

1) Download  & Unpack Apache HTTP server Package:

Download and unpack Apache http server package  from the location listed above, and unpack it.
Download Link: Apache Download
gzip -d httpd-2_x_NN.tar.gz
tar -xf httpd-2_x_NN.tar

2) Download  & Unpack PHP source Package:

Download Link: PHP Dowanlod
gunzip php-NN.tar.gz
tar -xf php-NN.tar

3) Build and install Apache:

cd httpd-2_x_NN
./configure --enable-so
make
make install

4) Start  & Start Apache:

/usr/local/apache2/bin/apachectl start
stop the  apache to configure php
/usr/local/apache2/bin/apachectl stop

5) Configure & Build  PHP Package:

cd ../php-NN
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
make
make install

6)Setup your php.ini

cp php.ini-development /usr/local/lib/php.ini
You may edit your .ini file to set PHP options. If you prefer having php.ini in another location, use --with-config-file-path=/some/path in step 5.

If you instead choose php.ini-production, be certain to read the list of changes within, as they affect how PHP behaves.

7) Edit your httpd.conf to load the PHP module:

LoadModule php5_module modules/libphp5.so

8) Tell Apache to  parse PHP extensions:

If you instead choose php.ini-production, be certain to read the list of changes within, as they affect how PHP behaves.
let's have Apache parse .php files as PHP. Add to httpd.conf file.
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>
Or, if we wanted to allow .php, .php2, .php3, .php4, .php5, .php6, and .phtml files to be executed as PHP, but nothing else, we'd use this:
FilesMatch "\.ph(p[2-6]?|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>
And to allow .phps files to be handled by the php source filter, and displayed as syntax-highlighted source code, use this:
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

9) Start Apache:

/usr/local/apache2/bin/apachectl start
OR
service httpd restart
That’s all.

Monday 20 October 2014

WEBMIN- Managing Unix Systems Graphically

What is Webmin?

Webmin is a web-based interface for system administration for Unix. Using any modern web browser, you can setup user accounts, Apache, DNS, file sharing and much more.

Demo:

http://webmin-demo.virtualmin.com/   login: demo &  password: demo.

Download Link:

How to Install:

Install on RedHat/CentOS/Fedora:

If you are using the RPM version of Webmin, first download the file from the downloads page , or run the command :
[root@UMLinux1 ~]# wget http://prdownloads.sourceforge.net/webadmin/webmin-1.710-1.noarch.rpm

and then run the command

[root@UMLinux1 ~]# rpm -U webmin-1.710-1.noarch.rpm
The rest of the install will be done automatically to the directory /usr/libexec/webmin, the administration username set to root and the password to your current root password. You should now be able to login to Webmin at the URL http://localhost:10000/.Or if accessing it remotely, replace localhost with your system's IP address.

If you want to connect from a remote server and your system has a firewall installed, see this page for instructions on how to open up port 10000.

Install on Debian:

If you are using the DEB version of webmin, first download the file from the downloads page , or run the command :
[root@UMLinux1 ~]# wget http://prdownloads.sourceforge.net/webadmin/webmin_1.710_all.deb

then run the command :

[root@UMLinux1 ~]# dpkg --install webmin_1.710_all.deb
The install will be done automatically to /usr/share/webmin, the administration username set to root and the password to your current root password. You should now be able to login to Webmin at the URL http://localhost:10000/. Or if accessing it remotely, replace localhost with your system's IP address.

How to Stop& Start Webmin Services:

In order to start the Webmin service on CentOS (Linux) you will need to issue the following command:
[root@UMLinux1 ~]# service webmin start
You can check to make sure that Webmin is running by issuing the following command:
[root@UMLinux1 ~]# service webmin status
Webmin (pid 1729) is running
[root@UMLinux1 ~]#
If you wish to configure your server to ensure that the Webmin service is started at boot time you can issue the following command:
[root@UMLinux1 ~]# chkconfig --level 3 webmin on
To verify that Webmin will start at boot, issue the following command:
[root@UMLinux1 ~]# chkconfig --list webmin
webmin 0:off 1:off 2:off 3:on 4:off 5:off 6:off
[root@UMLinux1 ~]#
In the previous listing, Webmin is listed to start in run level 3, which is the default run level that the dedicated servers boot into.

Saturday 11 October 2014

Run VIO commands from the HMC using "viosvrcmd" without VIOs Passwords

Recently  we got a situation where  in we don't know the passwords of  either padmin/root of VIOS  but need to run commands in VIOs.

Found an interesting command  in HMC  called "viosvrcmd",which will enble us to run commands on VIOs through HMC.
viosvrcmd -m managed-system {-p partition-name | --id partition-ID} -c "command" [--help]
Description: viosvrcmd issues an I/O server command line interface (ioscli) command to a virtual I/O server partition.

The ioscli commands are passed from the Hardware Management Console (HMC) to the virtual I/O server partition over an RMC session.

RMC does not allow interactive execution of ioscli commands.
-m    VIOs managed system name

-p    VIOs hostname

--id  The partion ID of the VIOs

Note:You must either use this option to specify the ID of the partition, or use the  -p option to specify the partition's name. The --id and the -p options are mutually exclusive.

-c    The I/O server command line interface (ioscli) command to issue to the virtual I/O      server partition.

Note: Command must be enclosed in double quotes. Also, command cannot contain the      semicolon (;), greater than (>), or vertical bar (|) characters.

--help  Display the help text for this command and exit.
Here is an example:
hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "ioslevel"
2.2.0.0
Since  we can't give the ; or > or |  in the command , if you need to process the output using filters , you can use that after "".
hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "lsdev -virtual" | grep vfchost0
vfchost0         Available   Virtual FC Server Adapter

What if  you want to run  command as root (oem_setup_env) ,  

got a method from internet
hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "oem_setup_env
> whoami"
root

You can  run in one shot like below

hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "oem_setup_env\n whoami"
root
If you need to run multiple commands , you can use them by assiging the commands to a variable and call the variable in place of the command parameter.
hscroot@umhmc:~>command=`printf  "oem_setup_env\nchsec -f /etc/security/lastlog -a unsuccessful_login_count=0 -s padmin"`

hscroot@umhmc:~>viosvrcmd -m umfrm570 -p umvio1 -c "$command"

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.

Monday 21 July 2014

Howto fix delay in SSH Login

Have you ever faced  login delays  when you tried to connect to the Linux systems, if yes this is happening due to  reverse DNS look-up  query that is been made to DNS Server.

We can fix this issue as mentioned below steps:

1) Take /etc/ssh/sshd_config  backup
# cp -p /etc/ssh/sshd_config /etc/ssh/sshd_config.`date '+%m-%d-%Y_%H:%M:%S'`
2) Edit  /etc/ssh/sshd_config  on sshd  Server
vi /etc/ssh/sshd_config

  And add this DNS option to the file:

  UseDNS no
3) Now add the following line to your /etc/resolv.conf
   options single-request-reopen 4) Restart ssh daemon
# service sshd restart
Sometimes adding the client's net address to the server's /etc/hosts can fix this issue  which is an alternative method. 

Monday 14 July 2014

Install SNMP Service on RHEL or CentOS


Install SNMP Service on RHEL or CentOS

In this article  we are going to learn  how to install and start  SNMP service in RHEL/CentOS.

We need  to have  net-snmp rpm package installed on the servers , generally it would come with repository.


1. Install net-snmp with yum:

#yum install net-snmp
[root@umserv]# yum install net-snmp
Loaded plugins: dellsysid, fastestmirror
Loading mirror speeds from cached hostfile
-----
-----
Dependencies Resolved

========================================================================================================================================================================
Package    Arch         Version          Repository        Size
========================================================================================================================================================================
Installing:
net-snmp     x86_64   1:5.3.2.2-22.el5_10.1    updates  708 k
Installing for dependencies:
 lm_sensors     x86_64  2.10.7-9.el5       base     525 k
Updating for dependencies:
 net-snmp-libs  i386    1:5.3.2.2-22.el5_10.1    updates  1.3 M
 net-snmp-libs  x86_64  1:5.3.2.2-22.el5_10.1    updates  1.3 M

Transaction Summary
========================================================================================================================================================================
Install      2 Package(s)
Update       2 Package(s)
Remove       0 Package(s)

Total download size: 3.8 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): lm_sensors-2.10.7-9.el5.x86_64.rpm        | 525 kB     00:01
(2/4): net-snmp-5.3.2.2-22.el5_10.1.x86_64.rpm   | 708 kB     00:02
(3/4): net-snmp-libs-5.3.2.2-22.el5_10.1.i386.rpm      | 1.3 MB     00:04
(4/4): net-snmp-libs-5.3.2.2-22.el5_10.1.x86_64.rpm    | 1.3 MB     00:03
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total   168 kB/s | 3.8 MB     00:23
Running rpm_check_debug
Running Transaction Test

Finished Transaction Test
Transaction Test Succeeded
Running Transaction
----
----
Installed:
  net-snmp.x86_64 1:5.3.2.2-22.el5_10.1

Dependency Installed:
  lm_sensors.x86_64 0:2.10.7-9.el5

Dependency Updated:
  net-snmp-libs.i386 1:5.3.2.2-22.el5_10.1 net-snmp-libs.x86_64 1:5.3.2.2-22.el5_10.1

Complete!
[root@umserv]#

2. Simple SNMP configuration:

mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.old
Add   below configuration to /etc/snmp/snmpd.conf
rocommunity  public  xxx.xxx.xxx.xxx
rocommunity  public   127.0.0.1
syslocation  "HYD, UM DataCenter"
syscontact  surya@unixmantra.com

Replace xxx.xxx.xxx.xxx with the IP address of the server that you want to allow SNMP lookups from:
rocommunity public xxx.xxx.xxx.xxx

3. Start the SNMP service, and set it to auto-start on reboot:

/etc/init.d/snmpd start
chkconfig snmpd on
Note:If you have a firewall configured, ensure that you have UDP port 161 open to your SNMP lookup server.

4) Validation:

On your SNMP lookup server, you can do the following to perform a quick SNMP test to ensure that it’s working.
snmpwalk -v 2c -c public xxx.xxx.xxx.xxx or snmpwalk -v 1 -c public -O e 127.0.0.1
[root@umserv ~]# snmpwalk -v 1 -c public -O e 127.0.0.1
SNMPv2-MIB::sysDescr.0 = STRING: Linux umserv 2.6.18-92.1.17.el5 #1 SMP Mon Jul 14 06:07:13 IST 2014 i686
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (16748) 0:02:47.48
SNMPv2-MIB::sysContact.0 = STRING: surya@unixmantra.com
SNMPv2-MIB::sysName.0 = STRING: umserv
SNMPv2-MIB::sysLocation.0 = STRING: "HYD, UM DataCenter"
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (1) 0:00:00.01
...
...
Yes, it is working

Tuesday 24 June 2014

AIX RC Scripts

We need some applications  should be stopped and started gracefully without manual intervention during the reboots . Order to serve this purpose , we use  rc scripts in all unix flavors including AIX  .

So, how do rc.scripts work:
  1. Write a single script, put it into /etc/rc.d/init.d, make sure the script accepts a single parameter of start or stop and does the right thing.
  2. In /etc/rc.d/rc2.d create a link (ln -s) to the script in init.d called Sxxname where xx is a number that dictates where in comparison to other scripts in the directory your script will execute (lower number first).
  3. In /etc/rc.d/rc2.d create a link to the script in init.d called Kxxname where xx is a number which dictates when the script is run to stop your app in comparison to other scripts in the directory (lower number first).
Note: Its just convention to place scripts in /etc/rc.d/init.d and make  soft links  in /etc/rc.d/rc2.d. But its need not mandatory to keep  scripts in /etc/rc.d/init.d.

Example RC Script:

#!/usr/bin/ksh

ulimit -c 0

case "$1" in
start )
        ps -ef | grep -v grep | grep myengine > /dev/null
        ret=$?
        if [ $ret -gt 0 ]; then
                /var/myengine/bin/startup.sh
        fi
        ;;
stop )
        PID=$$
        for i in myengine-app1 myengine-app2 myengine-app3 myengine-app4; do
                ps -ef | grep $i | grep -v grep | awk '{print $2}' >> /tmp/myengine.$PID
        done
        while read line; do
                kill $line
        done < /tmp/myengine.$PID
        rm /tmp/myengine.$PID
        ;;
* )
        echo "Usage: $0 (start | stop)"
        exit 1
esac

Example Creating Symbolic Links

This is an example on creating symbolic links for automatic startup for tivoli. tivoli should start first (meaning a low Sxx) and stop last (meaning a high Kxx):
umadmin@umserve1:/etc/rc.d/rc2.d>sudo ln -s /etc/rc.d/init.d/rc.tivoli S20tivoli
umadmin@umserve1:/etc/rc.d/rc2.d>sudo ln -s /etc/rc.d/init.d/rc.tivoli K70tivoli

Thursday 19 June 2014

How to Convert OpenSSH to SSH2 and vise versa

The program SSH (Secure Shell) provides an encrypted channel for logging into another computer over a network, executing commands on a remote computer, and moving files from one computer to another. SSH provides strong host-to-host and user authentication as well as secure encrypted communications over the Internet.

SSH2 is a more secure, efficient, and portable version of SSH .

Connecting two servers running different type of SSH can be a danting task if you does not know how to convert the key. In this article ,we are going to learn about how to convert  keys   SSH( OpenSSH) to SSH2.

How to Generate OpenSSH(SSH v1) key :

umadm@umixserv1 [/home/umadm/.ssh]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/umadm/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/umadm/.ssh/id_rsa.
Your public key has been saved in /home/umadm/.ssh/id_rsa.pub.
The key fingerprint is:
5b:ac:ea:c3:25:cf:2d:31:a2:aa:83:76:4b:a2:c9:eb umadm@umixserv1
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|         .       |
|        S o      |
|. o   . .+       |
|+o o + oo        |
|Bo.   =.         |
|#Eo..oo.         |
+-----------------+
umadm@umixserv1 [/home/umadm/.ssh]$
Here we get two encrypted keys  callled   private key( called id_rsa) and public key id_rsa.pub  undr ~$HOME/.ssh directory.
  
You can generate dsa key by using below command.
#ssh-keygen -t dsa

Convert SSH2 to  OpenSSH(SSH):


The command below can be used to convert an SSH2 private key into the OpenSSH format:
ssh-keygen -i -f path/to/private.key > path/to/new/opensshprivate.key
The command below can be used to convert an SSH2 public key into the OpenSSH format:
ssh-keygen -i -f path/to/publicsshkey.pub > path/to/publickey.pub
Here  -i ==> SSH to read an SSH2 key and convert it into the OpenSSH format

Convert OpenSSH(SSH) to SSH2:

The  reverse  process to convert an OpenSSH key into the SSH2 format in the event that a client application requires the other format. This can be done using the following command:

OpenSSH to SSH2 Private key conversion:
ssh-keygen -e -f path/to/opensshprivate.key > path/to/ssh2privatekey/ssh2privatekey
OpenSSH to SSH2 Public key conversion:
ssh-keygen -e -f path/to/publickey.pub > path/to/ssh2privatekey/ssh2publickey.pub
Here  -e ==> SSH to read an OpenSSH key file and convert it to SSH2 format

Note:If you need passwordless authentication  b/w two different hosts , you need to convert the publickey as per the destination server SSH version and  append the public key to   ~/.ssh/authorized_keys or  ~/.ssh2/authorized_keys at destination server.

Sunday 8 June 2014

How to Remove a Virtual SCSI Disk

This document describes the procedure to remove a virtual disk in a volume group on a Virtual I/O Client, to map the virtual scsi disk to its corresponding backing device, and to remove the backing device from the Virtual I/O Server.  Please, read the entire document before proceeding.

This document applies to AIX version 5.3 and above.

In a Virtual I/O environment, the physical devices are allocated to the VIO server.  When there is a hardware failure (disk or adapter may go bad) on the VIO server, unless the VIO server has some type of redundancy, that will have an impact on the VIO client whose virtual disks are being served by the failing device.  The impact may be loss of connectivity to the virtual scsi disks, unless there is some type of redundancy (MPIO or LVM mirroring) on the client partition. 

This document does NOT apply to any of the following environments:
1. If the virtual disk is in a shared volume group (i.e HACMP, etc)
2. If the virtual disk is part of rootvg volume group.

 Removing a Physical Volume from a Volume Group

 The following steps are needed to remove a virtual disk from the VIO client, and they are later discussed in more detail:

1. Deallocate all the physical partitions associated with the physical volume in the volume group.
2. Remove the physical volume from the volume group
3. Map the virtual scsi disk on the VIO client partiton to the backing device on the VIO server.
4. Remove the virtual scsi disk definition from the device configuration database.
5. Remove the backing device.

At this point, a new virtual scsi can be added to the VIO client in place of the virtual disk that was removed in the case where this procedure was done as a result of a hardware failure on the VIO server partition.

 1. Deallocating the physical partitions

 In the following procedure, we will be using hdisk4 in the example, as the virtual scsi disk wanting to be removed from the VIO client.

First, we need to determine the logical volumes defined on the physical volume we want to remove. This can be done by running:

# lspv -l hdisk#            
where hdisk# is the virtual scsi disk to be removed.

Example:

# lspv -l hdisk4
hdisk4:
LV NAME          LPs      PPs      DISTRIBUTION       MOUNT POINT
fslv00               2          2          00..02..00..00..00    /test
loglv00             1          1          00..01..00..00..00    N/A
rawlv                 30        30         00..30..00..00..00    N/A

If the hdisk name no longer exists, and the disk is identifiable only by its 16-digit PVID (you might see this from the output of lsvg -p <VGname>), substitute the PVID for the disk name. For example:

# lspv -l 00c2b06ef8a9f98a

You may receive the following error:
     0516-320 : Physical volume 00c2b06ef8a9f98a is not assigned to
     a volume group.
If so, run the following command:
# putlvodm -p `getlvodm -v <VGname>` <PVID>
VGname refers to your volume group, PVID refers to the 16-digit physical volume identifier, and the characters around the getlvodm command are grave marks, the backward single quote mark. The lspv -l <PVID> command should now run successfully.  To determine the VGname associated with that physical volume use lspv hdisk#.
If another disk in the volume group has space to contain the partitions on this disk, and the virtual scsi disk to be replaced has not completely failed, the migratepv command may be used to move the used PPs on this disk. See the man page for the migratepv command on the steps to do this.
If the partitions cannot be migrated, they must be removed. The output of the lspv -l <hdisk#>, or lspv -l <PVID>, command indicates what logical volumes will be affected. Run the following command on each LV:
# lslv <LVname>
The COPIES field shows if the LV is mirrored. If so, remove the failed copy with:

# rmlvcopy <LVname> 1 <hdisk#>
hdisk# refers to all the disks in the copy that contain the failed disk. A list of drives can be specified with a space between each. Use the lslv -m <LVname> command to see what other disks may need to be listed in the rmlvcopy command. If the disk PVID was previously used with the lspv command, specify that PVID in the list of disks given to the rmlvcopy command.  The unmirrorvg command may be used in lieu of the rmlvcopy command. See the man pages for rmlvcopy and unmirrorvg, for additional information.
If the logical volume is not mirrored, the entire logical volume must be removed, even if just one physical partition resides on the drive to be replaced and cannot be migrated to another disk. If the unmirrored logical volume is a JFS or JFS2 file system, unmount the file system and remove it. Enter:
# umount /<FSname>
# rmfs /<FSname>

If the unmirrored logical volume is a paging space, see if it is active. Enter:
# lsps -a

If it is active, set it to be inactive on the next reboot.  Enter:
# chps -a n <LVname>

Then deactivate it and remove it remove it by entering:
# swapoff /dev/<LVname>
# rmps <LVname>

Remove any other unmirrored logical volume with the following command:
# rmlv <LVname> 

2. Remove the physical volume from the volume group.

 In the case where the virtual scsi disk to be replaced is the only physical volume in the volume group, then remove the volume group, via:

# exportvg <VGname>

This will deallocate the physical partitions and will free up the virtual disk.  Then, remove the disk definition, as noted on step 3.

In the case where there are more than one physical volumes.  Using either the PVID or the hdisk name, depending on which was used when running lspv -l in the preceding discussion, run one of the following:

# reducevg <VGname> <hdisk#>
# reducevg <VGname> <PVID>

If you used the PVID value and if the reducevg command complains that the PVID is not in the device configuration database, run the following command to see if the disk was indeed successfully removed:

# lsvg -p <VGname>

If the PVID or disk is not listed at this point, then ignore the errors from the reducevg command.

3. How to map the virtual scsi disk (on the client partiton) to the physical disk (on the server partition)

 In the following example, we are going to determine the mapping of virtual scsi disk, hdisk4

On the VIO client:

The following command shows the location of hdisk4:

# lscfg -vl hdisk4
  hdisk4           U9117.570.102B06E-V1-C7-T1-L810000000000  Virtual SCSI Disk Drive

where V1 is the LPAR ID (in this case 1), C7 is the slot# (in this case 7), and L81 is the LUN ID. 
Take note of these values.

Next, determine the client SCSI adapter name, by ‘grep’ing for the location of hdisk4's parent adapter, in this case, V1-C7-T1:

# lscfg -v|grep V1-C7-T1
  vscsi4           U9117.570.102B06E-V1-C7-T1                Virtual SCSI Client Adapter
        Device Specific.(YL)........U9117.570.102B06E-V1-C7-T1
  hdisk4           U9117.570.102B06E-V1-C7-T1-L810000000000  Virtual SCSI Disk Drive

where vscsi4 is the client SCSI adapter.

On the HMC:

Run the following command to obtain the LPAR name associated with the LPAR ID

# lshwres -r virtualio --rsubtype scsi -m <Managed System Name> --level lpar

To get the managed system name, run
# lssyscfg -r sys -F name

Then, look for the "lpar_id" and "slot_num" noted earlier.  In our case, the VIO client lpar id is 1 and the slot # is 7.

In the following example, the managed system name is Ops-Kern-570.  The VIO client partition name is kern1.
The VIO Server partition name is reg33_test_vios.

# lshwres -r virtualio --rsubtype scsi -m Ops-Kern-570 --level lpar
...
lpar_name=kern1,lpar_id=1,slot_num=7,state=1,is_required=0,adapter_type=client,
remote_lpar_id=11,remote_lpar_name=reg33_test_vios,remote_slot_num=23,backing_devices=none
...
Take note of the remote_lpar_id (11) and the remote_slot_num (23).  Then, in the same output, look for a line that corresponds to "lpar_id 11, slot # 23
...
lpar_name=reg33_test_vios,lpar_id=11,slot_num=23,state=1,is_required=0,adapter_type=server,
remote_lpar_id=any,remote_lpar_name=,remote_slot_num=any,backing_devices=none
...
So in this case, VIO server reg33_test_vios is serving virtual scsi disk, hdisk4, on the VIO client, kern1.
            
On the VIO Server:

Go to the VIO Server associated with the LPAR ID obtained in the previous step, in our case reg33_test_vios.
As padmin, run the following command to display the mapping, which should match the mapping obtained from the HMC obtained above.

$ lsmap -all|grep <VIO server lpar ID>-<VIOS slot#>

For example,
$ lsmap -all|grep V11-C23
where V11 is the VIO server lpar_id and C23 is the slot #

The cmd will return something similar to

vhost21         U9117.570.102B06E-V11-C23                    0x00000001

In this case, vhost21 is the server SCSI adapter mapped to our VIO client lpar id 1 (0x00000001).

Next, list the mapping for the vhost# obtained previously.

$ lsmap -vadapter vhost21
SVSA               Physloc                                                Client Partition ID
---------------         --------------------------------------------    ------------------
vhost21            U9117.570.102B06E-V11-C23     0x00000001

VTD                  virdisk01                      
LUN                  0x8100000000000000
Backing device clientlv01                     
Physloc               

Take note of the VTD and Backing device name.  In this case, the backing device mapped to virtual scsi disk, hdisk4, is logical volume, clientlv01, and it is associated with Virtual Target Device, virdisk01.

4. Remove the virtual scsi disk definition from the device configuration database on the VIO client

 To remove the vscsi definition, run

# rmdev -dl hdisk#

Ensure you know the backing device associated with the virtual scsi disk being removed prior to issuing the rmdev command.  That information will be needed in order to do clean up on the server partition.  Refer to the section "How to map the virtual scsi disk (on the client partition) to the physical disk (on the server partitions)".

 5. Remove the backing device on the VIO server

 The peripheral device types or backing devices currently supported are
·                logical volume
·                physical volume
·               optical device starting at v1.2.0.0-FP7 (but not currently supported on System i)

Prior to removing the backing device, the virtual target device must be removed first. To do so, run the following as padmin:

$ rmdev -dev <VTD name>
$ rmlv <LVname>

or you can remove both the VTD and logical volume in one command by running:

$ rmvdev -vtd <VTD name> -rmlv

In the case where the backing device is a physical volume, then, removing the virtual target device completes this document.

If you need to determine the physical device and volume group that the logical volume belongs to, you can issue the following commands prior to running rmlv or rmvdev.
$ lslv -pv <LVname>    List the physical volume that the logical volume specified resides on.
$ lslv <LVname>          Shows the characteristics of the logical volume, including the volume group name, # of mirrored copies, etc.

In our example, the backing device is a logical volume, clientlv01, and it resides on the physical device, hdisk3:

$ lslv -pv clientlv01
clientlv01:N/A
PV                COPIES        IN BAND       DISTRIBUTION 
hdisk3            080:000:000   100%          000:080:000:000:000

$ rmdev -dev virdisk01
virdisk01 deleted

$ rmlv clientlv01
Warning, all data contained on logical volume clientlv01 will be destroyed.
rmlv: Do you wish to continue? y(es) n(o)? y
rmlv: Logical volume clientlv01 is removed.

Related Documentation

Virtual I/O Server Website
http://www14.software.ibm.com/webapp/set2/sas/f/vios/home.html

Relevant Links in Documentation Tab:
http://www14.software.ibm.com/webapp/set2/sas/f/vios/documentation/home.html
·                     IBM System p Advanced POWER Virtualization Best Practices Redbook
·                     IBM System Hardware Information Center
·                     VIOS Commands Reference

Saturday 7 June 2014

AIX NFS Error - RPC: 1832-010 Authentication error fixing



AIX NFS Error and Solution - RPC: 1832-010 Authentication error
[root-umserv1][/]> mount umserv2:/repos /mymnt
mount: 1831-008 giving up on:
umserv2:/repos
vmount: The file access permissions do not allow the specified action.
NFS fsinfo failed for server umserv2: error 7 (RPC: 1832-010 Authentication error)
To fix this issue check "nfs_use_reserved_ports" value , if its 0 set it to 1
[root-umserv1][/]> nfso -a | grep port
portcheck = 0
nfs_use_reserved_ports = 0

[root-umserv1][/]> nfso -po portcheck=1
Setting portcheck to 1
Setting portcheck to 1 in nextboot file

[root-umserv1][/]> nfso -po nfs_use_reserved_ports=1
Setting nfs_use_reserved_ports to 1
Setting nfs_use_reserved_ports to 1 in nextboot file

[root-umserv1][/]> mount umserv2:/repos /mymnt
[root-umserv1][/]>

Monday 19 May 2014

Simple Script to Document LVM info in AIX

Friends here is a small script which can pull AIX OS LVM information of the server and if want it in a file re-direct the  output of the script into a file.This is best useful when your are doing system reboots and upgrades.

Script:

#!/bin/ksh
#
# Simple script to document LVM configurations.
#
exec 2>&1
printf "AIX DISK AND LVM INFORMATION\n"
printf "*********************************************************\n"

printf "\nDF\n"
printf "==========================\n"
df -k

printf "\nVOLUME GROUPS:\n"
printf "==========================\n"
lsvg

printf "\n\nPHYSICAL VOLUMES:\n"
printf "==========================\n"
lspv

printf "\n\nPVs BY VOLUME GROUP\n"
printf "==========================\n"
lsvg | while read VG; do
    VGLIST="$VGLIST $VG"
    printf "\n$VG\n"
    printf "--------------------------\n"
    lspv | grep $VG
done

printf "\n\nPV INFORMATION:\n"
printf "==========================\n"
lspv | while read PV; do
    printf "\n$PV\n"
    printf "--------------------------\n"
    lspv $PV
done

printf "\n\nVG INFORMATION\n"
printf "==========================\n"
for VG in $VGLIST; do
    printf "\n$VG\n"
    printf "--------------------------\n"
    lsvg $VG
    lsvg -l $VG
done

printf "\n\nLV INFORMATION\n"
printf "==========================\n"
for VG in $VGLIST; do
    printf "\nVolume Group: $VG\n"
    printf "--------------------------\n"
    lsvg -l $VG | egrep -v "^$VG:" | egrep -v "^LV NAME" | while read LV JUNK;
do
        printf "\nLogical Volume: $LV\n"
        printf "--------------------------\n"
        lslv $LV
    done
done