Thursday, February 19, 2009

HP-UX: How Do I configure routing or add route?

You can use route command to configure routing. Syntax is as follows:
route add net {network-address} netmask {subnet} {router-address}

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:
# 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

Wednesday, February 11, 2009

Finding file and directories : HP-UX

The find command recursively descends a directory locating all the files that meet the criteria given on the command line. Without any options the find command will take no action on the files it finds, so the -print option is used to write the found files to standard output. The format of the find command is:

find path_name_list [options]

Where path_name_list is one or more directories.

% find . -name Makefile -print
/home/huron2/admin/scot/tutorial/Makefile
%
The . is a directory abbreviation for the current directory. The -name option specifies that only files with the given name should be found. The name option can include wildcard character:
% find . -name "core*" -size +3 -mtime +7 -exec rm -i {} \; -print
/home/huron2/admin/scot/core: ? (y/n) y
/home/huron2/admin/scot/core
%
==>Some Options to Find
--------------------------------------------------------------------
-name file Find files named file

-size n Find files that contain size...
n exactly n blocks (1 block = 512 bytes)
+n more than n blocks
-n less than n blocks

-mtime n Find files that were modified
n exactly n days ago
+n more than n days ago
-n less than n days ago

-exec cmd Execute command cmd on each file

-type type Find files that match the type
f ordinary file
d directory
b block device
c character device
p named pipe
--------------------------------------------------------------------
Actions can be taken when files are found by using the -exec option. The -exec option uses the {} (left curly-brace right curly-brace) syntax to specify the current file that find has found. The exec command ends with the \; syntax. If we did not have the print option at the end we would not get a confirmation the file had been removed.

...ciao...

Tuesday, February 10, 2009

How do I start hpux network service?

Use following command to start HP-UX network service:

/etc/init.d/net start
OR
/sbin/init.d/net start
Please note that your network configuration file is /etc/rc.config.d/netconf . Here is my sample /etc/rc.config.d/netconf file:

# cat /etc/rc.config.d/netconf
Output:
HOSTNAME=deephpux < --change hostname here OPERATING_SYSTEM=HP-UX LOOPBACK_ADDRESS=127.0.0.1 INTERFACE_NAME[0]=lan0 IP_ADDRESS[0]=192.168.1.100 <--change IP address here SUBNET_MASK[0]=255.255.255.0 <--change subnet mask here BROADCAST_ADDRESS[0]="" DHCP_ENABLE[0]="0" <--Do you wanna DHCP? set 1 to use DHCP

You can also set IP address using ifconfig command:
# ifconfig lan0 192.168.1.200 netmask 255.255.255.0 up

See or get current IP address information with ifconfig command:
# ifconfig lan0

......Life is short, enjoy every moment!

Sunday, February 8, 2009

LVM for HP-UX

The following are an overview of how to
create volumes in LVM for HP-UX.

1) Add your disks, and verify their device
names. The the command:

# ioscan -fnC disk

2) Next, place the disks you wish to use for
volumes under LVM control. This
is done by converting a disk into
a "Physical Volume" (pv). The command
used is:

# pvcreate

example: #pvcreate /dev/rdsk/c1t0d0

Note: You can use the "-f" option
to "force" the creation, which keeps
LVM for asking for verification...
the "Would you like to proceed? (y/n)"

3) Now, create a device path for the volume group.
Do this by creating a directory in /dev
by the name of the volume group.

# mkdir /dev/

example: # mkdir /dev/vg01

4) Then create a "group node" in that directory.
The process looks like this:

# mknod /dev//group c 64

example: # mknod /dev/vg01/group c 64 0x030000

Note: The minor number follows the following patern:
0x030000
0x040000
0x050000
.....

5) You can now create your Volume Group (vg) to which
the Physical Volumes will be assigned. A VG
is similar to a Disk Group in Veritas. The
format is:

# vgcreate /dev/ ....

example: # vgcreate /dev/vg01 /dev/dsk/c1t0d0

Note: The PV DevPaths don't use a partition
designation (sX). You can specify as many PV's
to add to a VG as you like on this one line.

6) Next create a Logical Volume (lv). This is the "volume"
itself, which will contain the file system.

# lvcreate /dev/

example: # lvcreate /dev/vg01

Note: This will create a 0 length volume. It
will also create two new files in the vg dev
directory: lvol1 and rlvol1. Being: Logical
Volume 1, and Raw Logical Volume 1. You can
have multiple LV's per VG.

Note(2): lvcreate with no options will create
a concat volume. To create striped volumes,
use the options:
-i This is the Vx equiv to column numbers.
-I This is the Vx equiv to a stripe width in kb.
-m Number of mirrors. Can be "1" or "2".
-L The size of the new volume in megabytes.

7) Now you can extend to Logical Volume to the length
you desire. To extend to it's max, do the
following:

a) Run the command: # vgdisplay
example: # vgdisplay /dev/vg01

b) Look for the two lines: "Total PE" and "PE Size"
PE stands for "Physical Extent". If you
multiply the number of "Total PE" by
"PE Size" you will get the total size of
the disk that is usable, usually in megabytes.

NOTE: LVM breaks PV's into Physical Extents.
These are like blocks in LVM. PE Size is
the size of each PE. Total PE is the
number of PE's avalible to the volume group.
The "PE Size" is variable, default is "4M"
but it can be reset to any desired size,
during VG creation. The options avable to
"vgcreate" are:
-e Max Num of PE's for this VG. Default: 1016
Max PE cannot exceed: 65535
-l Max Num of LV's for this VG. Default: 255
-p Max Num of PV's for this VG. Default: 16
Max PV cannot exceed: 255
-s Size of each PE for this VG. Default: 4
PE Size must be a power of 2.
-x Can the VG be grown? Default: y

c) With the number you got by multiplying "Total PE" by "PE Size"
you have the total lenth of the VG. To make all disks
in the VG be used by 1 LV, and to use all the space,
extend the Logical Volume with the command:

# lvextend -L

example: # lvextend -L 3200 /dev/vg01/lvol1

This would extend VG01's LV 1 out to (NOT by) 3.2G.
Remember the size is defaulted to Megabytes.

8) You can now create your filesystem with:

# newfs -F

example: # newfs -F vxfs /dev/vg01/rlvol1

9) Now mount the filesystem like usual:

# mount /dev/vg01/lvol1 /mydatavolume

Done!

Friday, February 6, 2009

HP-UX LVM listing

- Monitor LVM with the following commands:
bdf : Similar to a Solaris style "df -k" output.
pvdisplay :Display PV Information
vgdisplay :Display VG Information
lvdisplay :Display LV Information

- Remove LVM Objects with the commands:
pvremove: Removes a PV Device (ie: /dev/dsk/c0t1..)
vgreduce : Remove a PV from a VG Binding
use as: vgreduce /dev/vg01 /dev/dsk/c0t1d0
vgremove : Removes a VG, only done when there
is only ONE disk left in the VG.
lvremove Removes a LV.

To remove a complete volume you must unmount the fs, then
remove the LV, then reduce the VG to all but one disk. Then
remove the VG. Then you only need to remove each PV untill
you have normal disks again, not under LVM control.

- Here's a list of commands:


----VG-----
vgcfgbackup
vgchange
vgcreate
vgexport
vgimport
vgremove
vgcfgrestore
vgchgid
vgdisplay
vgextend
vgreduce
vgscan

---LV----
lvchange
lvdisplay
lvlnboot
lvreduce
lvrmboot
lvcreate
lvextend
lvmmigrate
lvremove

---PV----
pvchange
pvck
pvcreate
pvdisplay
pvmove
pvremove

- There are 3 LVM Objects:

----------------------------
| Logical Volume |
----------------------------
\/ \/ \/ \/
----------------------------
| Volume Group |
----------------------------
\/ \/ \/ \/
----------------------------
| Physical Volume |
----------------------------

or: Disks are used to create PV's,
which we group into VG's, from
which we create LV's which
contains the filesystem we use.

..:-)

Thursday, February 5, 2009

How To Write First UNIX Korn Shell Script Program

Korn shell scripting under UNIX / Linux can be used to automate lots of stuff. It easy to write a shell script. You must know how to use a text editor such as vi to write a script.

Write a shell program to print knowledge is power on screen. Type the following command to open file:

#vi hello.ksh

The first line should be as follows:

#!/bin/ksh

It is called a shebang. It consists of a number sign and an exclamation point character (#!), followed by the full path to the interpreter such as /bin/ksh. All scripts under UNIX execute using the interpreter specified on a first line.
Next append code as follows:

# A shell script to print message
# Written by Ninenok - Feb/5/2008
print "Knowledge is power"

Save and close the file. At the end your script should look like as follows:

#!/bin/ksh
# A shell script to print message
# Written by Ninenok - Feb/5/2008
# ------------------------------
print "Knowledge is power"

Set executable permission

Type the following command to set executable permission:
chmod +x hello.ksh

Run your korn shell script

Type the following command:
./hello.ksh

Sample output:

Knowledge is power

---------------------
..enjoy..:-)

Tuesday, February 3, 2009

add a remote line printer to HP-UX

The easiest way is using SAM (SMH on 11.31).

#sam
Select
1.Printers and Plotters,
2.LP Spooler
3.Printers and Plotters
4.Add Remote Printer/plotter from the action menu.

--ciao.....

Monday, February 2, 2009

Delete Files Older Than x Days

The find utility on hp-ux allows you to pass in a bunch of interesting arguments, including one to execute another command on each file. We'll use this in order to figure out what files are older than a certain number of days, and then use the rm command to delete them.

Command Syntax

find /path/to/files* -mtime +5 -exec rm {} \;

Note that there are spaces between rm, {}, and \;

Explanation

  • The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.
  • The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.
  • The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.

This should work on Ubuntu, Suse, Redhat, or pretty much any version of linux.