Category Archives: Howto

Run command on multiple linux servers from windows

Learn how to run the same/repetitive command on multiple Linux servers from the Windows machine. This trick uses command line putty ‘plink’ utility.

One of the major concerns for sysadmin is to run the same/repetitive command on multiple Linux servers in infra when there is no centralized tool available. In this post, we are going to see how to run a command on multiple Linux servers in one go. There is no need of saving your account password anywhere and even no need to have expect function in your source machine!

Pre-requisite

  • Windows machine with plink downloaded on it (download plink here)
  • Linux servers should be reachable from a windows machine

How to do it

plink is a putty command-line utility. Using plink we will be able to connect to the server by supplying IP, username, password on the command line. plink can be invoked from a command prompt on windows.

C:\Users\noname\Desktop>plink -ssh user1@10.10.1.11 -pw password@123 (hostname; date)
testserver
Tue Nov  1 12:54:33 IST 2016

C:\Users\noname\Desktop>

Goto Windows command prompt by typing cmd in a run window (windows key + r). Navigate to folder where plink executable is kept and then type in plink command as above.

  • ssh: protocol to connect
  • id@server IP
  • pw: account password
  • Commands to execute on Linux server in braces.

This is how plink works. Now to execute the same command on multiple servers we see below example. We will connect to 3 servers and execute hostname & date command.

First, put all 3 server’s IP addresses in single file ip_list.txt. Then execute simple for loop on that file as below in command prompt. This is a very basic batch script.

C:\Users\noname\Desktop>FOR /F "tokens=1,2* delims=," %G IN (C:\Users\noname\Desktop\ip_list.txt) DO plink -ssh user1@%G -pw password@123 (hostname; date)

testserver
Tue Nov  1 12:54:33 IST 2016

testserver1
Tue Nov  1 12:54:36 IST 2016

testserver2
Tue Nov  1 12:54:39 IST 2016

C:\Users\noname\Desktop>

Voila! all server’s command output is there! Commands executed on all servers in one go.

This is very useful when you need to check some single line outputs from all servers or if you want to run account refresh commands on all servers in one go.

Howto get Disk serial number in HPUX

Howto tutorial to get a hard disk serial number from the HPUX server. Learn to obtain disk information using the CSTM command prompt.

Disk serial number is a unique number which is a key identification of disk on the system. While disks are plugged in and online it’s hard to trace their serial numbers physically. Normally serial numbers can be identified on disk which is printed on sticker physically. But if the disk is plugged into the system and currently online it’s hard to observe it physically from all sides and get the serial numbers. In such a condition, we can get serial numbers from OS by running commands. Commands read disk information from disks and extract it for us.

How to get a serial number

Here we are going to see how to get a serial number of the disk which is attached to a server running HPUX. Normally everyone knows diskinfo command to get basic disk information.

# diskinfo  /dev/rdsk/c1t1d0
SCSI describe of /dev/rdsk/c1t1d0:
             vendor: HP 36.4G
         product id: ST336754LC
               type: direct access
               size: 35566480 Kbytes
   bytes per sector: 512

In diskinfo output we get basic information on disk like its vendor, size, product ID, etc. Note that you need to use the raw device in command argument i.e. disk name with rdsk not dsk.

But we are not getting a serial number of the disk here. We will use CSTM to get this information. CSTM is Command-line Support Tool Manager. Its a part of the Online Diagnostic tool which is used for real-time hardware monitoring on HP platforms.

Running cstm will take you to cstm prompt where different commands can be run.

# cstm
Running Command File (https://z5.kerneltalks.com/usr/sbin/stm/ui/config/.stmrc).

-- Information --
Support Tools Manager


Version A.59.05

Product Number B4708AA

(C) Copyright Hewlett Packard Co. 1995-2007
All Rights Reserved

Use of this program is subject to the licensing restrictions described
in "Help-->On Version".  HP shall not be liable for any damages resulting
from misuse or unauthorized use of this program.

cstm>

At cstm prompt run below command to get serial number info.

cstm>selclass qualifier hard;info;wait;infolog
-- Updating Map --
Updating Map...
-- Converting multiple raw log files to text. --
Preparing the Information Tool Log for each selected device...

.... server1  :  10.10.1.5 ....

-- Information Tool Log for SCSI Disk on path 0/0/1/1.0.0 --

Log creation time: Mon Oct 31 09:56:06 2016

Hardware path: 0/0/1/1.0.0


Product Id:       ST373455LC#36     Vendor:           HP 36.4G
Device Type:      SCSI Disk         Firmware Rev:     HPC8
Device Qualifier: HP36.4GST373455LC#36  Logical Unit:     0
Serial Number:    3LQ3VVTS000099075C5W
Capacity (M Byte):          34732.89
   Block Size:              512
   Max Block Address:       71132959
Smart Enabled:    TRUE
Error Logs
   Read Errors:                0    Buffer Overruns:        N/A
   Read Reverse Errors:      N/A    Buffer Underruns:       N/A
   Write Errors:               0    Non-Medium Errors:        2
   Verify Errors:              0

=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=

CSTM prompt can be exited using quit command.

cstm>quit
-- Exit the Support Tool Manager --
Are you sure you want to exit the Support Tool Manager?

Enter Cancel, Help, or OK: [OK] ok
#

If you do not wish to enter prompt / do interactive stuff then the above tasks can be accomplished in a single one-liner too.

# echo "selclass qualifier hard;info;wait;infolog"|cstm
Running Command File (https://z5.kerneltalks.com/usr/sbin/stm/ui/config/.stmrc).

-- Information --
Support Tools Manager


Version A.59.05

Product Number B4708AA

(C) Copyright Hewlett Packard Co. 1995-2007
All Rights Reserved

Use of this program is subject to the licensing restrictions described
in "Help-->On Version".  HP shall not be liable for any damages resulting
from misuse or unauthorized use of this program.

cstm>selclass qualifier hard;info;wait;infolog
-- Updating Map --
Updating Map...
-- Converting multiple raw log files to text. --
Preparing the Information Tool Log for each selected device...

.... server1  :  10.10.1.5 ....

-- Information Tool Log for SCSI Disk on path 0/0/1/1.0.0 --

Log creation time: Sat Oct 29 23:33:37 2016

Hardware path: 0/0/1/1.0.0


Product Id:       ST373455LC#36     Vendor:           HP 36.4G
Device Type:      SCSI Disk         Firmware Rev:     HPC8
Device Qualifier: HP36.4GST373455LC#36  Logical Unit:     0
Serial Number:    3LQ3VVTS000099075C5W
Capacity (M Byte):          34732.89
   Block Size:              512
   Max Block Address:       71132959
Smart Enabled:    TRUE
Error Logs
   Read Errors:                0    Buffer Overruns:        N/A
   Read Reverse Errors:      N/A    Buffer Underruns:       N/A
   Write Errors:               0    Non-Medium Errors:        2
   Verify Errors:              0

					

Hyperthreading in HPUX

Learn what is hyperthreading or logical CPU in HPUX. Checklist of commands to enable or disable hyperthreading on hardware or OS level.

What is hyperthreading

It’s a new feature supported in HPUX 11iv3. It’s supported only on the Integrity system architecture (Itanium dual-core processors). Basically, after enabling hyperthreading (will be called HT in this post henceforth) on the server, it allows a single process to spawn threads on multiple cores at a time. This speeds up the processing and in turns enhances performance.

How to enable it

HT can be enabled at the hardware level and also on the OS level. While toggling this settings reboot is required for changes to take effect.

Enable/disable HT at the hardware level

There are several ways to do it depends on your server’s environment.

From HPUX OS shell by setting -HT (-m parameter) to on or off in setboot configuration. Also for vpars one can use parmodify command.

# setboot -m on
OR
# setboot -m off

# parmodify -T y
OR
# parmodify -T n

From EFI shell i.e. during boot

EFI> cpuconfig threads on
OR
EFI> cpuconfig threads off

From vPar monitor i.e. vpmon prompt

vpmon> threads on
OR
vpmon> threads off
Enable/disable HT at OS level 

This can be done by setting kernel parameter logical CPU attribute to 1 on 0 in kernel configurations.

# kctune lcpu_attr=1
OR
# kctune lcpu_attr=0

You need to reboot the system after making these changes so that kernel will boot with HT feature.

Create nice text banner in HPUX

Learn how to create text banners on the HPUX terminal. These banners can be used to show in the message of the day or user login screen so that the message is flashed to the user without getting ignored.

Have you ever wondered those ASCII text banner you see when you log in to the server, how people create them? Today we will see one of the methods to design ASCII banner made out of # symbols!

This process uses  HPUX native commands but there are other ways to do it in the Linux server as well. Check here how to create beautiful ASCII text banners in Linux.

In HPUX we have command banner native with OS. This command should be supplied with words. It will echo out supplied arguments typed in # marks which are 6 rows high. See below example :

$ banner kerneltalk

 #    #  ######  #####   #    #  ######  #        #####    ##    #       #    #
 #   #   #       #    #  ##   #  #       #          #     #  #   #       #   #
 ####    #####   #    #  # #  #  #####   #          #    #    #  #       ####
 #  #    #       #####   #  # #  #       #          #    ######  #       #  #
 #   #   #       #   #   #   ##  #       #          #    #    #  #       #   #
 #    #  ######  #    #  #    #  ######  ######     #    #    #  ######  #    #

There is a limitation to this. Banner only takes the first 10 letters. It ignores all further characters. So basically it writes 10 characters using # symbol with 6-row height!

See below example where is counts only 10 characters to be shown.

$ banner 12345678910
   #     #####   #####  #       #######  #####  #######  #####   #####     #
  ##    #     # #     # #    #  #       #     # #    #  #     # #     #   ##
 # #          #       # #    #  #       #           #   #     # #     #  # #
   #     #####   #####  #    #  ######  ######     #     #####   ######    #
   #    #             # #######       # #     #   #     #     #       #    #
   #    #       #     #      #  #     # #     #   #     #     # #     #    #
 #####  #######  #####       #   #####   #####    #      #####   #####   #####

Minor design observations

When you use CAPS and SMALL letters, it shows all CAPS letters with 7-row height and SMALL with 6-row height.

$ banner TestingMe
#######                                                 #     #
   #     ######   ####    #####     #    #    #   ####  ##   ##  ######
   #     #       #          #       #    ##   #  #    # # # # #  #
   #     #####    ####      #       #    # #  #  #      #  #  #  #####
   #     #            #     #       #    #  # #  #  ### #     #  #
   #     #       #    #     #       #    #   ##  #    # #     #  #
   #     ######   ####      #       #    #    #   ####  #     #  ######

When you space in between, it will convert them to cartridge returns. So every character after space starts on a new line.

$ banner this is test

  #####  #    #     #     ####
    #    #    #     #    #
    #    ######     #     ####
    #    #    #     #         #
    #    #    #     #    #    #
    #    #    #     #     ####


    #     ####
    #    #
    #     ####
    #         #
    #    #    #
    #     ####


  #####  ######   ####    #####
    #    #       #          #
    #    #####    ####      #
    #    #            #     #
    #    #       #    #     #
    #    ######   ####      #

When you use only alphabets, there is always one blank row above output. If you use numbers, the output starts immediately on the next line of command. You can observe the above outputs.

These text banners can be used to show on user login session or in /etc/motd. They can flash important messages to user without getting ignored.

How to identify current boot disk in HPUX

When root disk is mirrored at OS level, its difficult to know which disk system is booted from. Learn here how to identify current boot disk in HPUX. 

There are a couple of ways by which you can identify boot disk from which the HPUX system is currently booted. This information is handy when HPUX is having root mirroring and if any maintenance activity needs to be carried out.

In such scenarios, one must know the current boot disk out of 2 root mirror disks. For example, if you have a root disk failure in the mirror then you must know if boot disk is damaged or not so that you can safely redirect IO to another disk/plan your maintenance.

Method 1

An easy method is to use setboot command which clearly states the primary boot disk.

# /usr/sbin/setboot -v
Primary bootpath : 2/0/0/3/0.0x6.0x0 (/dev/rdisk/disk40)
HA Alternate bootpath :
Alternate bootpath : 2/0/0/2/0.0x6.0x0 (/dev/rdisk/disk16)
 
Autoboot is ON (enabled)
Hyperthreading : OFF
: OFF (next boot)
 
----- output truncated -----

Method 2

This is a bit tricky. You need to use adb to get the hardware address of the booted disk. Then this hardware address can be traced back to disk name by matching in under ioscan output.

# echo "boot_string/S" | adb /stand/vmunix /dev/kmem
boot_string:
boot_string: (12/0/9/1/0.0.0;)/stand/vmunix

Method 3

Even by observing Syslog messages after boot, one can determine from which disk kernel was booted.

# grep "Boot device" /var/adm/syslog/syslog.log
Nov 15 18:44:18 myserver1 vmunix: Boot device's HP-UX HW path is: 2/0/0/3/0.0x6.0x0
.0

In the above output, it clearly mentions the hardware path of the disk from which the kernel was booted. Now, this hardware path can be matched with the device name in ioscan -fnCdisk output and a disk name can be obtained.

bdf command formatted output in hpux

Learn to get the neat, clean and tabbed output of bdf.  This left aligned and properly formatted bdf output is helpful for easier data processing.

Requirement :

bdf command output normally looks scattered especially when VG names are long. It will be difficult to grep out a proper pattern out of such output. Also, it’s not convenient to share this output over email/document when extra lines break exists.

In such scenarios, we need to have a properly formatted output of bdf. Also sometimes we require output with all its columns left-aligned.

Solution:

To remove line breaks from bdf output and get single row per entry output

See below normal bdf output. Note that the last 2 mount points have two-line entry since the filesystem column has long entry.

# bdf

Filesystem          kbytes    used   avail %used Mounted on
/dev/vg00/lvol3    2097152  737416 1349304   35% /
/dev/vg00/lvol1    1048576  206160  835928   20% /stand
/dev/vg00/lvol8    8388608 5475640 2902568   65% /var
/dev/vg00/lvol7    8388608 4655256 3713000   56% /usr
/dev/vg00/lvol4    2097152 1052368 1036888   50% /tmp
/dev/vg00/lvol6    8388608 6675168 1700112   80% /opt
/dev/vg00/lvol5     524288   49360  471256    9% /home
testserver01:/data
                   50574008 4541896 43463104    9% /data
/dev/vgdata/lvol1
                   918421504 591931608 306084338   66% /datastore

Now with inline awk we format the output to have one entry per row. Check below command output.

# bdf | awk '{if (NF==1) {line=$0;getline;sub(" *"," ");print line$0} else {print}}'

Filesystem          kbytes    used   avail %used Mounted on
/dev/vg00/lvol3    2097152  737408 1349312   35% /
/dev/vg00/lvol1    1048576  206160  835928   20% /stand
/dev/vg00/lvol8    8388608 5475640 2902568   65% /var
/dev/vg00/lvol7    8388608 4655256 3713000   56% /usr
/dev/vg00/lvol4    2097152 1052368 1036880   50% /tmp
/dev/vg00/lvol6    8388608 6675168 1700112   80% /opt
/dev/vg00/lvol5     524288   49360  471256    9% /home
testserver01:/data 50574008 4541896 43463104    9% /data
/dev/vgdata/lvol1 918421504 591931608 306084338   66% /datastore

To get left aligned bdf output

In the above output, columns are not aligned properly. We can even do that with the below argument.

# bdf | awk '///{printf("%-30s%-10s%-10s%-10s%-5s%-10sn",$1,$2,$3,$4,$5,$6)}'

/dev/vg00/lvol3               2097152   737408    1349312   35%  /
/dev/vg00/lvol1               1048576   206160    835928    20%  /stand
/dev/vg00/lvol8               8388608   5472792   2905392   65%  /var
/dev/vg00/lvol7               8388608   4655256   3713000   56%  /usr
/dev/vg00/lvol4               2097152   1052368   1036888   50%  /tmp
/dev/vg00/lvol6               8388608   6675168   1700112   80%  /opt
/dev/vg00/lvol5               524288    49360     471256    9%   /home

Please make a note that this awk won’t remove any line breaks from the output. So one can combine (with pipe |) both awk to get left aligned output with line breaks removed.

Left-aligned output with line breaks removed!

# bdf | awk '{if (NF==1) {line=$0;getline;sub(" *"," ");print line$0} else {print}}' |awk '///{printf("%-30s%-10s%-10s%-10s%-5s%-10sn",$1,$2,$3,$4,$5,$6)}'
/dev/vg00/lvol3               2097152   737408    1349312   35%  /
/dev/vg00/lvol1               1048576   206160    835928    20%  /stand
/dev/vg00/lvol8               8388608   5481008   2897240   65%  /var
/dev/vg00/lvol7               8388608   4655256   3713000   56%  /usr
/dev/vg00/lvol4               2097152   1052368   1036888   50%  /tmp
/dev/vg00/lvol6               8388608   6675168   1700112   80%  /opt
/dev/vg00/lvol5               524288    49360     471256    9%   /home
testserver01:/data            50574008  4541896   43463104  9%   /data
/dev/vgdata/lvol1             918421504 591931608 306084338 66%  /datastore

					

Highest size files in mount point

Search for the highest sized file in the mount point. Useful while dealing with full mount points and cleaning up files to free up space.


There are many instances in the life of sysadmin when his system starts throwing filesystem full events and its headache to search culprit. Here we are going to see a command to search and display files with high utilization in a mount point. This is very useful to dig down and target exactly huge/big files rather than wasting time on trimming/deleting small files.

For example, if you are facing /tmp is full. Below is the command to search for large files in the given mount point. Here we are using du i.e. disk usage command then sorting the output list in reverse order so that the highest size files come to the top. Then getting top 10 to display as a result.

# du -a /tmp | sort -nr  | head -n 10
3396448 /tmp
1801984 /tmp/Acasrro411704
994848  /tmp/software.depot
81088   /tmp/PACPTHP_00001.depot
77088   /tmp/OraInstall2008-03-19_09-39-20AM
76912   /tmp/OraInstall2008-03-19_10-15-28AM
76848   /tmp/OraInstall2008-03-19_09-39-20AM/jre/1.4.2
76848   /tmp/OraInstall2008-03-19_09-39-20AM/jre
76656   /tmp/OraInstall2008-03-19_10-15-28AM/jre/1.4.2
76656   /tmp/OraInstall2008-03-19_10-15-28AM/jre

Replace /tmp with a mount point of your choice while running it in your system.

There are also different ways you can trace the highest size hogger on a mount point. Below are few

To find the large file size above 5000

# find /var -xdev -size +5000
/var/opt/perf/datafiles/logglob
/var/opt/perf/datafiles/logproc
/var/opt/perf/datafiles/logdev
/var/opt/perf/datafiles/logtran
/var/opt/OV/log/SPISvcDisc/DBSPI_ORACLE_UNIX_discovery.trc
/var/opt/OV/log/osspi/osspi.log
----- output truncated -----





Top 10 large directories in the mount point 

# du -kx /var | sort -rn -k1 | head -n 10
6726048	/var
3962830	/var/opt
3471340	/var/opt/OV
2494362	/var/adm
2465390	/var/opt/OV/tmp
1512210	/var/opt/OV/tmp/OpC
1438642	/var/adm/openv/logs
1438642	/var/adm/openv
921030	/var/adm/sa
822672	/var/adm/openv/logs/bpdbm

Top 10 large files in the mount point

# find /var -type f -xdev -print | xargs -e ll | sort -rn -k5 | head -n 10
-rw-rw----   1 root       bin        1463238440 Nov  1 14:45 /var/opt/OV/tmp/OpC/msgagtdf
-rw-rw-r--   1 root       bin        944541567 Nov  1 14:52 /var/opt/OV/tmp/sqlnet.log
-rw-rw-rw-   1 oracle92   dba        307369984 Mar  5  2014 /var/opt/omni/tmp/rcvcat21945.exp
-rw-------   1 root       mail       187848937 Nov  1 14:01 /var/tmp/dead.letter
-rw-rw----   1 root       bin        84680704 Feb 16  2013 /var/opt/OV/tmp/OpC/msgagtdf-11975.gc
-rw-r--r--   1 root       bin        80937879 Nov  1 14:54 /var/opt/OV/log/osspi/osspi.log
-rwxrwxrwx   1 root       users      58566204 Nov  1 14:55 /var/adm/rrdtool/apcrss32.rrd
-rw-rw-r--   1 root       bin        55159884 May 25  2009 /var/opt/OV/installation/temp/bbc/fx/upload/DeplM22799
-rw-rw-r--   1 root       bin        55159884 May 18  2009 /var/opt/OV/installation/temp/bbc/fx/upload/DeplM22011
-rw-rw-r--   1 root       bin        55159884 Jun 30  2010 /var/opt/OV/installation/temp/bbc/fx/upload/DeplM10143