Sunday, 11 December 2011

shell script - awk tips

Print column1, column5 and column7 of a data file or output of any columns list
$awk ‘{print $1, $5, $7}’ data_file
$cat file_name |awk ‘{print $1 $5 $7}’
$ls –al |awk ‘{print $1, $5, $7}’ -- Prints file_permissions,size and date

Syntax of running an awk program
Awk ‘program’ input file(s)

List all files names whose file size greater than zero.
$ls –al |awk ‘$5 > 0 {print $9}’

List all files whose file size equal to 512bytes.
$ls –al |awk ‘$5 == 0 {print $9}’

print all lines
$awk ‘{print }’ file_name
$awk ‘{print 0}’ file_name

Number of lines in a file
$awk ‘ END {print NR}’ file_name

Number of columns in each row of a file
$awk ‘ {print NF’} file_name

Sort the output of file and eliminate duplicate rows
$awk ‘{print $1, $5, $7}’ |sort –u

List all file names whose file size is greater than 512bytes and owner is "oracle"
$ls –al |awk ‘$3 == "oracle" && $5 > 512 {print $9}’

List all file names whose owner could be either "oracle" or "root"
$ls –al |awk ‘$3 == "oracle" || $3 == "root" {print $9}’

list all the files whose owner is not "oracle
$ls –al |awk ‘$3 != "oracle" {print $9}’

List all lines which has atlease one or more characters
$awk ‘NF > 0 {print }’ file_name

List all lines longer that 50 characters
$awk ‘length($0) > 50 ‘{print }’ file_name

List first two columns
$awk ‘{print $1, $2}’ file_name

Swap first two columns of a file and print
$awk ‘{temp = $1; $1 = $2; $2 = temp; print }’ file_name

Replace first column as "ORACLE" in a data file
$awk ‘{$1 = "ORACLE"; print }’ data_file

Remove first column values in a data file
$awk ‘{$1 =""; print }’ data_file

Calculate total size of a directory in Mb
$ls –al |awk ‘{total +=$5};END {print "Total size: " total/1024/1024 " Mb"}’

Calculate total size of a directory including sub directories in Mb
$ls –lR |awk ‘{total +=$5};END {print "Total size: " total/1024/1024 " Mb"}’

Find largest file in a directory including sub directories
$ls –lR |awk ‘{print $5 "\t" $9}’ |sort –n |tail -1

Power path installation on hp-ux for load balancing

To install power path :
#swinstall -x autoreboot=true -x mount_all_filesystems=false -s /tmp/EMCPower.HP.4.1.0.tar EMCpower

#emcpreg -install (#Enter registration key)

#powermt config

#powermt set policy=so dev=all

# powermt display

Run powervadm list to confirm unique volume group naming and storage elements do not belong to any other PPVG volume group on the host.

#powervadm list

To create VG & lvol :
#powervg create -vg oracle10g -se c22t0d0 c22t0d1 c22t0d2 –continue

#powervol create -vg oracle10g -vol ora100gbr5v08 -ua -se c24t1d0

To view volume group information

#powervadm [list|show]

#powervadm show -tab

To view information about a specific volume group

#powervg [list|show] –vg volumename –vol

#powervg [list|show] –vg volumename –se

The -vol and the -se arguments are mutually exclusive.

Backup metadata

#powervmeta backup -vg oracle10g -f /tmp/oracle10g_metadata.81390

Destory Volumes and Volume Groups run the following commands

#powervol destroy –vg oracle10g –vol ora22gbr1v01

#powervg destroy –vg oracle10g

Disable root SSH login : How to ??

Disable Root SSH Login on HP UX

# cd /opt/ssh/etc

# vi sshd_config

Change the line:

PermitRootLogin yes

change into like below

PermitRootLogin no

save and exit

Then stop and restart SSH.

# /sbin/init.d/secsh stop

# /sbin/init.d/secsh start

You will then NOT be allowed to ssh as root.

==============================================


Disable Root SSH Login on Linux


#vi /etc/ssh/sshd_config

Find this section in the file, containing the line with “PermitRootLogin” in it.

#LoginGraceTime 2m
#PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6

Make the line look like this to disable logging in through ssh as root.

PermitRootLogin no

Then restart the sshd service:

# /etc/init.d/sshd restart

Wednesday, 30 November 2011

How to get cpu / processor / core info in Linux?

To get processor info we need to run below commands in Linux

1. #cat /proc/cpuinfo

or

2. #dmidecode

To get the core info in linux use the below commands. If the processor is dual core or quad core or single core processor means we will get the "core id"value in the below commands. If no core (single core) processor means we wont get the core id . so from the word "core id" we can get the processor is core processor or physical processor.

For examble here i took 2 servers ..

server1 - has 4 physical - single cored processors

server 2 - has 2 physical - dual core processors

4 Physical processor with no core (single core) means we will get o/p like below


root:server1# egrep "^processor|^cpu cores|^core id" /proc/cpuinfo
processor : 0
processor : 1
processor : 2
processor : 3
root:server1#

To get core info (whether core is there or not)

root:server1# grep core\ id /proc/cpuinfo |uniq -d |wc -l
0

To get total no of physical processor

root:server1# grep core\ id /proc/cpuinfo | grep -c \ 0$ | grep ^0$ >> /dev/null && grep -c processor /proc/cpuinfo || grep core\ id /proc/cpuinfo | grep -c \ 0$
4


Two dual core processor means (2- physical processor) we will get o/p like below


root:server2# egrep "^processor|^cpu cores|^core id" /proc/cpuinfo
processor : 0
core id : 0 ----------------- processor 1
cpu cores : 2
processor : 1
core id : 0 ----------------- processor 1
cpu cores : 2

processor : 2
core id : 1 ----------------- processor 2
cpu cores : 2
processor : 3
core id : 1 ----------------- processor 2
cpu cores : 2

root:server2#

To get core info run the below command

root:server2# grep core\ id /proc/cpuinfo |uniq -d |wc -l -------> this will give how many cores are there / if no core means it will give out put as 0.
2


To get how many physical processor is there on server ,then run below command

root:server2# grep core\ id /proc/cpuinfo | grep -c \ 0$ | grep ^0$ >> /dev/null && grep -c processor /proc/cpuinfo || grep core\ id /proc/cpuinfo | grep -c \ 0$
2


====================================

Friday, 25 November 2011

Mount DVD in unix ?

Use the following procedure to mount a DVD-ROM on HP-UX 11i v2 (B.11.23):

1. Log in as root
2. Insert the DVD into the DVD-ROM drive and wait for the drive's busy light to stop blinking.
3. Find the DVD-ROM device file name using the following command:

ioscan -fn -C disk | more
/dev/dsk/c1t2d0 is a typical device name.

4. Create the mount point under root(/):

mkdir /dvdrom

5. Mount the DVD onto the new directory as a file system. For example, the following command mounts the /dev/dsk/c1t2d0 device as the /dvdrom directory:

mount /dev/dsk/c1t2d0 /dvdrom

Route add in HP Unix

Let us assume your router address is 192.168.1.254 and network ID is 192.168.1.0/24, then you can type route command as follows:
# route add net 192.168.1.0 netmask 255.255.255.0 192.168.1.254
OR
To add a default route:
# route add default 192.168.1.254
Verify that (display) routing table is updated (display routing table):
# netstat -nr
Test it i.e. try to ping or send nslookup request:
# ping mycorp.com
To flush all routing entries use command [quite handy to clean your gordian knot ;)] :
# route -f
However if I reboot HPUX box then above routing entries gets removed. To pick up your setting upon each reboot your need to configure Routes in HPUX networking configuration file - /etc/rc.config.d/netconf. To add default router/gateway 192.168.1.254:

# vi /etc/rc.config.d/netconf
Add or modify following entries
ROUTE_DESTINATION[0]="default"
ROUTE_MASK[0]=""
ROUTE_GATEWAY[0]="192.168.1.254"
ROUTE_COUNT[0]="1"
ROUTE_ARGS[0]=""
Reboot HP-UX system/server to take effect

# shutdown -ry 0

Bundle All Patches in One Big Bundle - HP Unix

Creating one big bundle with all the extra patches you need to install will save your time during the upgrade/patching process and also prevent multiple reboots of your servers.

Create folder '/var/patches' with 'depot' and 'add' subfolders and copy the Quality Pack into '/var/patches/depot' and additional patches into '/var/patches/add' folder. Next you need to unpack the Golden Pack:

# swcopy -s /var/patches/depot/GOLDQPK11i_B.11.11.0612.459.depot \* @ /var/patches/depot/QPK

With swcopy copy all additional patches into this unpacked depot.


# for patch in /var/depot/app/*; do
echo ${patch}
swcopy -x enforce_dependencies=FALSE \
-x mount_all_filesystems=FALSE \
-x reinstall=TRUE -s ${patch} \* @ \
/var/patches/depot/QPK >> swcopy_patchs.log 2>&1 Verify that all the packages in the new bundle we create are OK.

# swverify -d -x mount_all_filesystems=FALSE \
-x enforce_dependencies=FALSE \* @ /var/patches/depot/QPK

Now, we have to revert the bundle into the original format for easier distribution.

# swpackage -x media_type=tape -s /var/patches/depot/QPK @ \
/var/patches/depot/GOLDQPK11i_B.11.11.0612.459.NEW.depot

You can use this file as any other regular depot file.

# swinstall -i -x patch_match_target=true -x autoreboot=true -s \
/var/patches/depot/GOLDQPK11i_B.11.11.0612.459.NEW.depot

Thursday, 24 November 2011

Recover OS using Ignite Backup

HP-UX have a software to backup the OS called "Ignite". It bundled with OS installed. The easy way to make a OS backup is using tape data cartridge. Just plug the tape to tape library, and run command "make_tape_recovery -AI".

To restore OS using recovery tape, go to MP (management processor) and boot to tape (Sequential media) and follow the intructions.

To simplify manage the archive of OS backup, we can utilize "Ignite Server". We can make OS backup to disk (via network) in another server (Ignite Server).The command is "make_net_recovery -s ignite_server -x inc_entire=vg00″.

To recovery OS using ignite server (Client and Ignite server in same IP subnet):

1. Boot the failed system to Ignite server (boot lan install or boot lan.ip_ignite_server install)
2. Do not interact with ISL
3. Select "Install HP-UX" and follow the instructions to fill about server configurations (network, hostname, etc)

4. Select recovery configurations to use
If clients to use is different subnet, we must use a boot helper server. the boot helper server have same subnet with client server. to setting up boot helper:

* for example: IP Ignite server is 10.2.2.1 & GW 10.2.2.254, OS to be restored is restore01 and target client is client01 (10.2.3.1 & GW 10.2.3.254)

1. Make sure the boot helper server have Ignite software with same version with client & Ignite server
2. Point the installation to Ignite server
# instl_adm -t 10.2.2.1
3. To verify the correct configuration in boot helper, run command instl_adm -d
4. Specify the temporary ip address at boot helper that client can use to boot. Edit /etc/opt/ignite/instl_boottab

5. Copy the CINDEX & recovery directory from source (OS to be restored) to target client (server use to restore).
at Ignite Server:
# cd /var/opt/ignite/clients/restore01
# find CINDEX recovery | cpio -pvdma ../client01
# edit CINDEX file at target client (/var/opt/ignite/clients/client01/CINDEX)
- make a full path for system_cfg, control_cfg & archive_cfg. (/var/opt/ignite/clients/client01/../…..)

6. Boot to boot helper or direct to ignite server

Add SWAP in HP Unix : How to ?

How to add SWAP in hp Unix

To create swap, you need a contiguous space on a disk/LUN.
Create vg01:

pvcreate /dev/rdsk/c25t0d0
pvcreate /dev/rdsk/c25t2d0
vgcreate -s 8 -p 128 /dev/vg01 /dev/dsk/c25t0d0 /dev/dsk/c25t2d0
vgchange -a y /dev/vg01

lvcreate -C y -L 16384 -n lvswap /dev/vg01

/usr/sbin/swapon -f -p 3 /dev/vg01/lvswap

add to /etc/fstab:

/dev/vg01/lvswap … swap pri=3 0 0

Unix- LVM commonly asked Interview questions..

Regular tasks
I) How to create a Volume Group (VG).
II) How to create a Logical Volume (LV) and mount the file system.

III) How to add a disk to a Volume Group
IV) How to increase the size of a logical volume without OnlineJFS
V) How to remove a Logical Volume
VI) How to reduce the size of a logical volume without OnlineJFS (advanced JFS)
VII) How to remove a disk from a volume group
VIII) How to remove a volume group
IX) How to increase the primary swap
X) How to create a secondary boot disk LVM Mirroring
XI) How to mirror a logical volume

How to relate a failing disk(lun) with its remote port (nport_id)

This is only for legacy HDW paths.

After a problem we had today with our SAN, we where loosing link(milisenconds) to only 1 path
of the four we have:

LVM: Performed a switch for Lun ID = 0 (pv = 0x00000000c0f9c000), from raw device 0x1f170600 (with priority: 0, and current flags: 0x40) to raw device 0x1f0f0600 (with priority: 1, and current flags: 0x0).

from syslog we get the raw device major/minor numer: 0x1f170700

With the minor we get to know our disk:
root:/> ls -l /dev/dsk | grep 170700
brw-r----- 1 bin sys 31 0x170700 May 4 2010 c23t0d7

From the disk the HDW path:
root:/> lssf /dev/dsk/c23t0d7
sdisk card instance 23 SCSI target 0 SCSI LUN 7 section 0 at address 0/0/4/0/0.97.11.19.24.0.7 /dev/dsk/c23t0d7

From the HDW path the san(port info)
0/0/4/0/0 ---> HBA
97.11.19 ---> san(n_port id) info
24.0.7 ---> scsi target lun

Now we need to convert these numers into hex 97.11.19:

97 -> 61
11 -> 0b
19 -> 13

And finally with fcmsutil we can find the nport id using our hex conversion 610b13:
root:/> fcmsutil /dev/td0 get remote all | grep -e 610b13 -e Port
Target N_Port_id is = 0x610b13
Port Type = N_PORT
Target Port World Wide Name = 0x50050763030846e2

So Now you can tell your SAN admins which is the wwn of the failing port.

Check Failed stats:
root:/> fcmsutil /dev/td0 devstat all | grep -E '(Nport|Failed)'
Device Statistics for Nport_id 0x610b13
Failed Open of previously opened device 6
Device Statistics for Nport_id 0x613713
Failed Open of previously opened device 5
Device Statistics for Nport_id 0x750b13
Failed Open of previously opened device 6

Bootup/Shutdown in HP unix

shutdown -r 0 –> reboot
shutdown -h now –> shutdown and halt
shutdown 0 –> shutdown to single user mode
reboot 0 –> reboot
init 1 – single user mode
hpux -is boots single user mode

1. Interupting the boot process:
a. Configuration Menu
b. Information Menu
c. Service Menu

2. GSP Mode
a. From the console hit
b. Hit at the GSP console login (default is no password)
c. Now low level commands can be entered
ps –> power status

To reboot to single user mode:

1. shutdown -r 0
2. hit during 10 sec window to interrupt reboot
3. enter:
4. interact with ipl? yes
5. hpux -is (i=init, s=single user)

Configure disk to use for veritas volume manager (VxVM)

1. Detect new disk -> dfsadm, cfgadm -c configure control_number
2. Labeling disk -> format, choose disk number, label
3. Configure disks
# vxdisksetup -i disk_name
or using vxdiskadm -> choose 1. Add or initialize one or more disks
4. make diskgroup
# vxdg init dg_name disk_name=device_name
* vxdg init backupdg backupdg01=Disk_24
5. make volume
# vxassist -g backupdg maxsize
2096883712
# vxassist -g backupdg make backuplv 2096883712
*size=output from vxassist -g dg_name maxsize
6. Start volume
# vxvol -g backupdg startall
7. Make Filesystem
# mkfs -F vxfs /dev/vx/rdsk/backupdg/backuplv
8. Mounting Filesystem
# mkdir /backup
# mount -F vxfs /dev/vx/dsk/backupdg/backuplv /backup
9. Edit /etc/vfstab

Verify the latest standard patch bundles

HP-UX 11i v1
# swlist -l bundle BUNDLE11i HWEnable11i GOLDBASE11i GOLDAPPS11i

HP-UX 11i v2
# swlist -l bundle BUNDLE11i HWEnable11i FEATURE11i QPKBASE QPKAPPS

HP-UX 11i v3
# swlist -l bundle BUNDLE11i HWEnable11i FEATURE11i QPKBASE

Verify latest available patches

After installing the latest standard patch bundles, that are delivered on a six month schedule, you need to check for the latest available patches for your products. Using any of the available tools to perform patch assestments of your systems will give you detailed information on the patches available.

Swapoff in HP Unix

# swapinfo -tam
Mb Mb Mb PCT START/ Mb
TYPE AVAIL USED FREE USED LIMIT RESERVE PRI NAME
dev 12288 0 12288 0% 0 - 1 /dev/vg00/lvol2
reserve - 391 -391
memory 1938 628 1310 32%
total 14226 1019 13207 7% - 0 -

# lvcreate -L 1024 -n swap2 /dev/vg01
Logical volume "/dev/vg01/swap2" has been successfully created with
character device "/dev/vg01/rswap2".
Logical volume "/dev/vg01/swap2" has been successfully extended.
Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg01.conf

# swapon -p 1 /dev/vg01/swap2

# swapinfo -tam
Mb Mb Mb PCT START/ Mb
TYPE AVAIL USED FREE USED LIMIT RESERVE PRI NAME
dev 12288 0 12288 0% 0 - 1 /dev/vg00/lvol2
dev 1024 0 1024 0% 0 - 1 /dev/vg01/swap2
reserve - 391 -391
memory 1938 628 1310 32%
total 15250 1019 14231 7% - 0 -

# swapoff /dev/vg01/swap2

# swapinfo -tam
Mb Mb Mb PCT START/ Mb
TYPE AVAIL USED FREE USED LIMIT RESERVE PRI NAME
dev 12288 0 12288 0% 0 - 1 /dev/vg00/lvol2
reserve - 391 -391
memory 1938 628 1310 32%
total 14226 1019 13207 7% - 0 -

# lvremove /dev/vg01/swap2
The logical volume "/dev/vg01/swap2" is not empty;
do you really want to delete the logical volume (y/n) : y
Logical volume "/dev/vg01/swap2" has been successfully removed.
Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg01.conf

subnet mask and default gateway

Subnet Mask:-

The mask is used to detrmine that which part of IP belonged to network or which part belong to host. E.g. if u have a IP 172.16.25.32 and its subnet mask is 255.255.0.0. then the 172.16 is network part , and 25.16 is host part. If subneting is enable then we can use some bit of host part in network .Subnet mask mainly use in subneting. for above example subnet mask is 255.255.255.0 the nwk address become 172.16.25. and the host part is 32.

Default gateway:-

For a simple LAN there is no use of default gateway, It is used when network communicate with other network. it is just like a Main gate of home when a person wanna go to outside from home or come inside he can only do the same by main gate. Same Concept used here. In network if the packet have address of same address then switch direct forward the packet to its desired destination. And if packet have another network address it should be come out from Default gate way. Basically it reduces the collision. subnetmask is just used to identify the class of ip address and its is used for subnetting of ip address for eg:-

ipaddress -192.168.1.2
subnetmask- 255.255.255.0
we can find N/W part that is 192.168.1 and Host part that is 2
the class of ip is C

where as default gateway is a ip address given to a router or ASDL modem which is used to communuicate with other N/Ws or internet

Difference : HPUX 11iv2 and 11iv3

Major difference is benifit of agile naming view of device files. Both legacy and persistent can be used simultaneously to access mass storage devices. It meant auto multipathing using persistent dsf was new in 11iv3. Multipathing concept was always there from begining, but were done manually using vgextend and all.

dvd clon

ioscan -m dsf

persistant and legacy names

nwmgr

swconfig

check_patches

LVM v.2 volume group

lvmadm -t

Extending a VxFS Filesystem (No Online JFS)

Extending a VxFS Filesystem (No Online JFS)

1. Verify that there is enough space in the volume group
vgdisplay
If there is not enough space then the volume group must be extended - see procedure below.

2. First lvextend the logical volume - 2 Options for lvextend:
a. lvextend -L /dev/VG_NAME/LV_NAME
b. lvextend -l /dev/VG_NAME/LV_NAME

3. Unmount the filesystem
4. extendfs -F vxfs /dev//r
Note: extendfs uses the raw logical volume name (ie rlvol1)

A. How to determine if you have Online JFS
swlist -l fileset | grep -i advanced

B. How to determine the filesystem type
grep /etc/fstab
Results should show the filesystem type (vxfs or hfs) in the return string

Add a Lun to a VG in a SG cluster 11.11/23

Once disk presented to host,
# pvcreate /dev/rdsk/cxtxdx
# vgextend /dev/vgname /dev/dsk/cxtxdx
# lvcreate -L /dev/vgname/lvname
# newfs -F vxfs -o largefiles /dev/vgname/rlvname
# cp -p /etc/cmcluster/pkgname/pkg.cntl /etc/cmcluster/pkgname/pkg.cntl.org
# vi /etc/cmcluster/pkgname/pkg.cntl
LV[33]=/dev/vgname/lvname; FS[33]=/oracle/ABN/sapdata20; FSMOUNT_OPT[33]="-o convosync=direct,mincache=direct,delaylog,nodatainlog"
(Add newly create Logical volume to pkg.cnt.file)

# vgexport -p -s -v -m /tmp/vgname.map /dev/vgname
# rcp /tmp/vgname.map nodee2:/tmp/vgname.map
# cp -p /etc/cmcluster/pkgname/pkg.cntl /etc/cmcluster/pkgname/pkg.cntl.node2
# rcp /etc/cmcluster/pkgname/pkg.cntl.node2 nodee2:/tmp/
(mount the mount point manually on the node where the vg is active now)

# mount -o convosync=direct,mincache=direct,delaylog,nodatainlog /dev/vgname/lvolname /oracle/ABN/sapdata20

On Adoptive Node :-
# vgexport /dev/vgname
# mkdir /dev/vgname
# ll /dev/vg*/group
# mknode /dev/vgname/group c 64 0x0X0000
# vgimport -p -s -v -m /tmp/vgname.map /dev/vgname -> (preview) if no error proceed below by removing -p
# vgimport -s -v -m /tmp/vgname.map /dev/vgname
# cp /tmp/pkg.cntl.node2 /etc/cmcluster/pkgname
# cp -p /etc/cmcluster/pkgname/pkg.cntl /etc/cmcluster/pkgname/pkg.cntl.org
# mv /etc/cmcluster/pkgname/pkg.cntl.node2 /etc/cmcluster/pkgname/pkg.cntl

Adding mirroring to the root vg - HP Unix

1. pvcreate -B /dev/rdisk/c2t2d0
Create the PV on the second disk so that LVM can manage it
-B makes it a bootable volume

2. mkboot /dev/rdsk/c2t2d0
Installs the boot files on the second disk

3. mkboot -a "hpux-lq (;0)/stand/vmunix" /dev/rdsk/c2t2d0
Creates an autoboot file on the disk, with information on how to boot

4. vgextend /dev/vg00 /dev/dsk/c2t2d0
extends the volume group to include this second disk.

5. vgdisplay -v vg00
To verify that the second disk is now part of the volume group

6. lvlnboot -v
To verify that the system thinks this disk can boot

7. lvextend -m 1 /dev/vg00/lvol1 /dev/dsk/c2t2d0
This extends the logical volume to the mirrored disk, effectively creating the mirrored copy.
This command needs to be run for each logical volume in the volume group