- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script awk for report size all vgs.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2006 11:44 PM
11-20-2006 11:44 PM
I have a script report size all vgs, but the script is not correct fully. This is my script.
awk 'BEGIN { num_lv=0}
/Cur LV/ {num=$NF}
/PE Size/ {meg=$NF}
/Alloc PE/ {pe=$NF}
/LV Name/ {lvname[++num_lv]=$NF}
/LV Size/ {lvname[num_lv,"size"]=$NF}
END {print "Total Mb used= ",vg=meg*pe
for (i=1;i<=num_lv;i++) {
pct=(lvname[i,"size"]/vg*100)
tot=tot+pct
printf
("%s%s%s%6.2f%10s","volume\t",lvname[i],"\tis",pct,"percent\n")}
printf "%26s%6.2f\n","total ",tot
print "\n"
for (i=1;i<=num_lv;i++) {
pct=(lvname[i,"size"]/vg*100)
pct=(int(pct))
printf ("%s\t",lvname[i])
for (n=1;n<=pct;n++) printf ("%c", "*")
print""}}
When I execute this, show me the error:
------------------------------------------
syntax error The source line is 1.
The error context is
awk >>> ' <<<
awk: Quitting
The source line is 1.
------------------------------------------
Whats wrong?
Thanks..
Claudemir
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2006 11:57 PM
11-20-2006 11:57 PM
Re: Script awk for report size all vgs.
You have an unpaired sigle quote beginning on line-1:
'BEGIN
Change line-1 to be two lines to read:
#!/usr/bin/awk
BEGIN { num_lv=0}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2006 12:14 AM
11-21-2006 12:14 AM
Re: Script awk for report size all vgs.
But I have other error in line 16:
root@hpdev01:/root/scripts:>awk -f report_size_vg
syntax error The source line is 16.
The error context is
>>> ("%s%s%s%6.2f%10s","volume\t",lvname[i],"\tis",pct,"percent\n")} <<<
awk: The statement cannot be correctly parsed.
The source line is 16.
syntax error The source line is 24.
Note: This scripts i get in the my book "POSIX Shell Programming", I'm need this script for monitoring environment.
Thanks is advance.
Claudemir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2006 12:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2006 12:28 AM
11-21-2006 12:28 AM
Re: Script awk for report size all vgs.
By the way, I should have specified the interpreter line as:
#!/usr/bin/awk -f
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2006 12:31 AM
11-21-2006 12:31 AM
Re: Script awk for report size all vgs.
Very, very very thanks a lot of.... :o)
it is functioning.
Claudemir.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2006 01:48 AM
11-21-2006 01:48 AM
Re: Script awk for report size all vgs.
# cat /usr/local/bin/vgttl
#!/bin/sh
/usr/local/bin/bdfmegs|grep vg |tr -s " " " "|cut -d" " -f 1-4|sort|
awk 'BEGIN {
prev="";
totals[0]=0;
totals[1]=0;
totals[2]=0;
gtotals[0]=0;
gtotals[1]=0;
gtotals[2]=0;
printf("%8s %14s %14s %14s\n","VG","Size(MB)","In use","Available");
}
{split($1,curr,"/");
if (prev!="" && prev!=curr[3])
{printf("%8s %14d %14d %14d\n",prev,totals[0],totals[1],totals[2]);
gtotals[0]+=totals[0];
gtotals[1]+=totals[1];
gtotals[2]+=totals[2];
totals[0]=0;
totals[1]=0;
totals[2]=0;
}
prev=curr[3];
totals[0]+=$2;
totals[1]+=$3;
totals[2]+=$4;
}
END {
gtotals[0]+=totals[0];
gtotals[1]+=totals[1];
gtotals[2]+=totals[2];
printf("%8s %14d %14d %14d\n",prev,totals[0],totals[1],totals[2]);
printf("%8s %14s %14s %14s\n","----","--------------","--------------","--------------");
printf("%8s %14d %14d %14d\n","Totl",gtotals[0],gtotals[1],gtotals[2]);
}'
And the bdfmegs script:
# cat /usr/local/bin/bdfmegs
#!/usr/bin/sh
#
# Ver 3.1 - Trap fsadm errors and change return code. Allow -vl
# or -lv combinations.
# Ver 3.0 - Rewrote using temp files to speed up code about 10:1
# Added -l option and ? or -? help
# Ver 2.1 - Added vxfs filesystem layout verrsion (2,3,4,etc)
# Added non-root check for -v option fsadm needs root
# permission for fsadm to read lvols directly.
# Ver 2.0 - Change Blks to blk/frag size and add largefile status
# Made: FSTYPE blk/frag and largefile optional with -v
# to reduce the width of the line
#
# Ver 1.2 - Expanded filesystem type to handle autofs
# Ver 1.1 - Added blocksize column for filesystem blocks
# Ver 1.0 - Original
# -----------------------------------------------------------------------
# Show bdf in megs for easy reading
#
# Usage: bdfmegs [ -v ] [ -l ] [ -? | ? ]
# bdfmegs [ -? | ? ]
# The width of the source filesystem will be adjusted to the
# longest path (ie, NFS or other long device filename). All
# fields are in megabytes (defined as Kbytes/1024). Field
# widths are 7 digits for multi-terabyte capability.
set -u
MYNAME=${0##*/}
TEMPDIR=/var/tmp/$MYNAME.$$
/usr/bin/mkdir $TEMPDIR
/usr/bin/chmod 700 $TEMPDIR
MNTLIST=$TEMPDIR/mountlist
BDFLIST=$TEMPDIR/bdflist
ERRLIST=$TEMPDIR/errlist
trap "/usr/bin/rm -rf $TEMPDIR;exit" 0 1 2 3 15
# These values are tied to the widths if the fields and the title.
typeset -R7 MTOT
typeset -R7 MUSED
typeset -R7 MAVAIL
typeset -R5 PERCENT
typeset -R2 BLKSIZE
typeset -i FRAGSIZE
typeset -R6 FSTYPE
typeset -R1 FSVERSION
# Process all options
PARAMS=$#
VERBOSE=/usr/bin/false
LOCALFS=/usr/bin/false
BDFOPTS=""
while [ $PARAMS -gt 0 ]
do
case $1 in
-v ) VERBOSE=/usr/bin/true
;;
-l ) LOCALFS=/usr/bin/true
BDFOPTS="$BDFOPTS -l"
;;
-lv | -vl ) LOCALFS=/usr/bin/true
BDFOPTS="$BDFOPTS -l"
VERBOSE=/usr/bin/true
;;
\? | -\? )
echo
echo "Usage:"
echo " $MYNAME [ -v ] [ -l ]"
echo
echo "where: -v = full details"
echo " -l = local filesystems only"
exit
;;
\* ) echo "Unknown option: $1"
echo
;;
esac
shift
PARAMS=$(( PARAMS - 1 ))
done
# Get a complete list of mountpoints
/sbin/mount -p $BDFOPTS > $MNTLIST
# For bdf, process the list and paste the 2-line data together
# into a file to speed things up
#
# The mechanism is to read all the params from each line. If the
# line has been split, only the source is on line 1 so the rest
# of the params are null when read, so if $TOT is blank, read
# the next line for the missing params.
/usr/bin/bdf $BDFOPTS |
while read FS TOT USED AVAIL PERCENT MNT
do
if [ "$TOT" = "" ]
then
read TOT USED AVAIL PERCENT MNT
fi
echo $FS $TOT $USED $AVAIL $PERCENT $MNT
done > $BDFLIST
# Check if -v was specified
# If so, check if this is root? If not, fsadm can't obtain details.
if $VERBOSE
then
if [ $(/usr/bin/id -u) -ne 0 ]
then
echo
echo "$MYNAME: root required for -v option"
echo
exit 1
fi
fi
# Find the longest source string with a sweep through mount -p
# Minimum length is 12 so typeset will pad on the right when
# needed.
MAXLEN=12
cat $MNTLIST | while read SOURCE MOUNTPOINT DUMMY
do
[ ${#SOURCE} -gt $MAXLEN ] && MAXLEN=${#SOURCE}
done
# Variable width typesets here
#
# By using eval, a variable typeset instruction can be created
# and then executed as part of the inline script.
# First is for the filesystem source string
# Second is to pad the title. Note that PAD must be typeset to
# a value greater than 0, so subtract 11 for the evaluation.
# (the minimum width for a source directory is 12 chars)
eval "typeset -L$MAXLEN FS"
eval "typeset -L$(( MAXLEN - 11 )) PAD=' '"
# Now get all filesystems including filesystem type
# Separate the mount point from FStype and source with a |
MYMOUNTS=$(cat $MNTLIST | /usr/bin/awk '{print $2"|"$3"|"$1}')
# Print the title line. $PAD is used to prorvide proper spacing for
# short to long source filesystem names. This must match the
# evaluated typeset value for $FS above. We'll split the line
# at %Used in order to have plain and verbose versions.
echo "File System $PAD Mbytes Used Avail %Used \c"
if $VERBOSE
then
echo " Type Bk/Fg Lrg Mounted on"
else
echo "Mounted on"
fi
# Now walk through each mountpoint gathering info
# We'll search through the $BDFLIST file for
# the bdf info.
for MNTINFO in $MYMOUNTS
do
MOUNTPOINT=$(echo $MNTINFO | cut -f1 -d\|)
SOURCE=$( echo $MNTINFO | cut -f3 -d\| )
FSTYPE=$( echo $MNTINFO | cut -f2 -d\| )
grep ^$SOURCE $BDFLIST | read FS TOT USED AVAIL PERCENT MNT
# do
MTOT=$(echo $TOT \
| /usr/bin/awk '{print int($1/1024+.5)}')
MUSED=$(echo $USED \
| /usr/bin/awk '{print int($1/1024+.5)}')
MAVAIL=$(echo $AVAIL \
| /usr/bin/awk '{print int($1/1024+.5)}')
echo "$FS $MTOT $MUSED $MAVAIL $PERCENT \c"
if $VERBOSE
then
# filesystem features
BLKSIZE=$(/usr/bin/df -g $MNT \
| /usr/bin/grep "file system block" \
| /usr/bin/awk '{print $1/1024}')
FRAGSIZE=$(/usr/bin/df -g $MNT \
| /usr/bin/grep "file system block" \
| /usr/bin/awk '{print $6/1024}')
VG="${FS%/*}"
LVOL="${FS##*/}"
# Check only vxfs and hfs for features
case $FSTYPE in
# For vxfs, fsadm gets info from mountpoint but hfs needs the
# raw lvol. NOTE: fsadm may detect consistency errors so trap
# these to an error file, summarize and set an error return code.
" vxfs" )
LGFILE=$(/usr/sbin/fsadm -F $FSTYPE $MNT 2>> $ERRLIST \
| /usr/bin/grep -F largefiles)
# VxFS version
FSVERSION=$(/usr/sbin/fstyp -v $VG/r$LVOL 2>> $ERRLIST \
| /usr/bin/grep version: \
| /usr/bin/awk '{print $2}')
FSTYPE="vxfs$FSVERSION"
# largefiles?
if [ $( echo $LGFILE | /usr/bin/grep -Fc no) -gt 0 ]
then
LG=" no"
else
LG="yes"
fi
;;
" hfs" )
if [ $(/usr/sbin/fsadm -F $FSTYPE $VG/r$LVOL 2>> $ERRLIST \
| /usr/bin/grep -Fc nolargefiles) -lt 1 ]
then
LG="yes"
else
LG=" no"
fi
;;
# All others
* ) LG=" "
;;
esac
echo "$FSTYPE ${BLKSIZE}/${FRAGSIZE}K $LG $MNT"
else
echo "$MNT"
fi
done
# Any errors?
if [ -s $ERRLIST ]
then
echo " -- Errors exist (fsadm and/or fstyp):"
cat $ERRLIST | while read REPLY
do
echo " -- $REPLY"
done
exit 1
fi
Rgds...Geoff