1753426 Members
4985 Online
108793 Solutions
New Discussion юеВ

Re: scripting ?

 
SOLVED
Go to solution
Mhanby
Regular Advisor

scripting ?

I am a newbie regarding scripting, and have been asked to script getting the Filesystem as well as what fs version.

I have the following:
bdf |awk '{print $1}тАЩ (which will give me each filesystem)

but drawing a blank on how to pass this variable to the following command:

and fstyp -v VARIABLE | grep -i version > new.file (which i believe would give me the version for each filesystem listed and send the info to a file)

Any suggestions would be appreciated!

Thanks!

9 REPLIES 9
Patrick Wallek
Honored Contributor
Solution

Re: scripting ?

something like this should come close:

for LV in $(bdf -l |awk '{print $1}')
do
VERS=$(fstyp -v ${LV} |grep -i version)
echo ${LV} - ${VERS}
done

Patrick Wallek
Honored Contributor

Re: scripting ?

This may be closer still:

for LV in $(bdf -l |awk '{print $1}' |grep -v Filesystem)
do
VERS=$(fstyp -v ${LV} |grep -i -e ^version -e ^hfs)
echo ${LV} - ${VERS}
done


This gets rid the heading in the bdf output and also takes into account any HFS file systems. It looks for "hfs" at the beginning of a line and echos that since HFS filesystems do not have a "version" line.
James R. Ferguson
Acclaimed Contributor

Re: scripting ?

Hi:

You might do:

# cat queryfs
#!/usr/bin/sh
bdf | awk 'NR==1 {next};print $1,$NF}' | \
while read DEV MNT
do
printf "%s %s " ${DEV} ${MNT}
fstyp -v ${DEV} | \
awk 'NR==1 {KIND=$1};
/^version|^hfs/ {print %s %s\n",KIND,$0}'
done
exit

Regards!

...JRF...
Bill Hassell
Honored Contributor

Re: scripting ?

The attached script will provide all the details you need. Run it as root with -v:

bdfmegs -v

To see all the other options, use -h or -?:

bdfmegs -h

Usage: bdfmegs [ -cghlNPpqstuVv ] [ ]
where:
-c # = Sort on column #
-d = Toggle divisor (1000 or 1024, current=1000)
-g = show gigabytes, otherwise megabytes
-h = Usage (return code=0, Usage to stdout)
-l = local (no NFS)
-M = skip (grep -v) mountpoints
-N = skip one or more volume groups
Repeat -N or use commas: -N vg10,vg24
-p ## = highlight % -ge ##
-P ## = show only % -ge ##
-q = suppress header line and no char enhancements
-s = summarize total, used and available
-t = specifc filesystem: (hfs vxfs nfs cdfs cifs autofs DevFS)
-u = usage (return code=0, Usage to stdout)
-v = verbose (type, version, largefiles)
(version info needs read permission for mountpoint)
-V = select one or more volume groups
Repeat -V or use commas: -V vg00,vg01

File(s) or dirpath(s) may be specified to reduce the output of bdfmegs:

bdfmegs -vg /usr/contrib/bin /var/tmp

If bdfmegs is run as bdfgigs (ie, a link), then -g is default.
(bdfmegs ver 5.5_Dec2009)


Bill Hassell, sysadmin
Mhanby
Regular Advisor

Re: scripting ?

Thanks to all. I will try to test them out soon! Thanks again!
Mhanby
Regular Advisor

Re: scripting ?

hi again! All your suggestions got me close, but still not quite there yet.... I still see a few lines which throws off the pattern: LV - version

For instance, this here's a few lines illustrating some of the outliers...

/dev/vgXX/lvolX - version: 3
/ddd/vgxxxxx/lvxname - version: 3
39452672 -
/dev/vgyyyyy/lvyname - version: 3
23412736 -
/dev/vgzzzzz/lvzname - version: 4


Any further suggestions what caused the issue and how I can resolve it?

Thanks!


James R. Ferguson
Acclaimed Contributor

Re: scripting ?

Hi (again):

I'm sorry, it appears that I dropped or otherwise mangled some of my original post. Try:

# cat queryfs
#!/usr/bin/sh
bdf | awk '{if (NF==1) {line=$0;getline;sub(" *"," ");
print line$1,$NF} else {print $1,$NF}}' | \
while read DEV MNT
do
printf "%s %s " ${DEV} ${MNT}
fstyp -v ${DEV} | awk 'NR==1 {KIND=$1};
/^version|^hfs/ {printf "%s %s\n",KIND,$0}'
done
exit

...

Regards!

...JRF...

Bill Hassell
Honored Contributor

Re: scripting ?

> hi again! All your suggestions got me close, but still not quite there yet.... I still see a few lines which throws off the pattern: LV - version

Are the original bdf lines split? This is an annoying feature of bdf which is why I wrote bdfmegs. To get a clean, 1-liner output from bdf, do this:

bdf -l | while read FS TOT USED AVAIL PERCENT MNT
do
if [ $FS != "Filesystem" ]
then
if [ "$TOT" = "" ]
then
read TOT USED AVAIL PERCENT MNT
fi
echo $FS $TOT $USED $AVAIL $PERCENT $MNT
fi
done

This will give you a clean list of mountpoints. But you can get exactly what you want with bdfmegs:

bdfmegs -vq | awk '{print $NF,"-", $(NF-2)}'
/ - 5
/stand - na
/var - 5
/usr - 5
/tmp - 5
/opt - 5
/home - 5
/crashFiles - 6



Bill Hassell, sysadmin
James R. Ferguson
Acclaimed Contributor

Re: scripting ?

Hi (again):

Oops, now I dropped the code that skips the header of 'bdf'. This fixes that and handles multi-line 'bdf' output:

# cat queryfs
#!/usr/bin/sh
bdf | awk 'NR==1 {next};{if (NF==1) {line=$0;getline;sub(" *"," ");
print line$1,$NF} else {print $1,$NF}}' | \
while read DEV MNT
do
printf "%s %s " ${DEV} ${MNT}
fstyp -v ${DEV} | awk 'NR==1 {KIND=$1};
/^version|^hfs/ {printf "%s %s\n",KIND,$0}'
done
exit

# ./queryfs
/dev/vg00/lvol3 / vxfs version: 6
/dev/vg00/lvol1 /stand vxfs version: 5
/dev/vg00/lvol8 /var vxfs version: 6
/dev/vg00/lvol7 /usr vxfs version: 6
/dev/vg00/lvol6 /tmp vxfs version: 6
/dev/vg01/lvol1 /sysdev vxfs version: 6
/dev/vg01/lvol2 /patches vxfs version: 6
/dev/vg00/lvol5 /opt vxfs version: 6
/dev/vg00/lvol4 /home vxfs version: 6

Regards!

...JRF...