Tag Archives: BEGIN

For Loop & SUM

By Daniel Gate

HTML Code:

pcmpath query device |awk 'BEGIN{print "DEVICE NAMEtSERIAL"} /DEVICE NAME/ {printf "%st", $5; getline; print substr($2, length($2)-3)}'


This script returns output like below to pull out “DEVICE NAME SERIAL”.

HTML Code:

......
hdisk28 110B
hdisk29 1112
hdisk30 1115
hdisk31 1116
hdisk32 1128
hdisk33 112D
hdisk34 112E
hdisk35 1147
hdisk36 1148
hdisk37 1149
hdisk38 114A
hdisk39 114B
hdisk40 114C
hdisk41 114D
hdisk42 114E
hdisk43 116B
hdisk44 116C
hdisk45 116D
hdisk46 116E
.....


The script below is to pull out the disk size.

HTML Code:

for disk in `pcmpath query device |awk 'BEGIN{print "DEVICE NAMEtSERIAL"} /DEVICE NAME/ {printf "%st", $5; getline; print substr($2, length($2)-3)}' |awk '{print$1}'`
do
printf "%st" $disk; bootinfo -s $disk
done


But, what I need to have is the sum of hdisks with the output:

HTML Code:


List of the output first:

DEVICE NAME SERIAL SIZE
hdisk28 110B 36864
hdisk29 1112 36864
hdisk30 1115 36864
hdisk31 1116 24576
hdisk32 1116 16384
......

and then add them up as Sub-Total and Grand Total followed by:

DISK SUMMARY in MB
SIZE: 36864 NUMBER OF DISKS: 3 SUB-TOTAL: 110592
SIZE: 24576 NUMBER OF DISKS: 1 SUB-TOTAL: 24576
SIZE: 16384 NUMBER OF DISKS: 1 SUB-TOTAL: 16384
....
GRAND TOTAL ======================== xxxxxxxx


Please let me me know how to get the disk size per each disk size and disk summary (SIZE: NUMBER OF DISKS: SUB-TOTAL & GRAND TOTAL)

Source: FULL ARTICLE at The UNIX and Linux Forums

Sort log files based on numeric value in the filename

By alex2005Hi,
I have a list of log files as follows:

Code:
name_date_0001_ID0.log
name_date_0001_ID2.log
name_date_0001_ID1.log
name_date_0002_ID2.log
name_date_0004_ID0.log
name_date_0005_ID0.log

name_date_0021_ID0.log

name_date_0025_ID0.log

…………………………………
name_date_0028_ID0.log
name_date_0029_ID0.log
name_date_0030_ID0.log
I need to generate numbers from 1 to 30 and match them with their equivalent extracted from the filename (if duplicates are found, than multiply the rows with the numbers of duplicates) and then search for a pattern inside the log file.
With help from internet I managed to complete each operation, but I do not know to how to merge them in a single command.
Generate numbers from 1 to 30 using :

Code:
awk ‘BEGIN { for (i = 1; i
Source: The UNIX and Linux Forums