I am writing a script to keep check on free disk space, and I would like to find a way to parse $LINE (see code below) into a numeric value (for free disk space percentage) and a string value (for mount point). If possible, I would like to avoid sed or any additional use of awk since I am not very familiar with those utilities. All help is appreciated. Thanks in advance.
ScriptName=$(basename $0) # Equivalent shorthand code is: ${0##*/}
TempFile_NME=${DBA_TMP}/${ScriptName}.tmp
df -h | grep / | awk '{ print $5, $6 }'>$TempFile_NME
while read LINE
do
echo "$LINE"
done < $TempFile_NME
Your script writes out line to the screen. Can you paste a few lines, or all lines, into a follow-up message? Especially since it appears that there is more than one field of information being displayed.
Most likely a cut command can pull the data apart.
> cat scan_data
#! /bin/bash
while read zf
do
numb=$(echo "$zf" | cut -d"%" -f1)
driv=$(echo "$zf" | cut -d"%" -f2)
drivt=$(printf "%-40s" "$driv")
numbt=$(printf "%9.3f" "$numb")
echo "For your disk drive = $drivt ... your percentage full is $numbt"
done<inputf
> scan_data
For your disk drive = / ... your percentage full is 15.000
For your disk drive = /devices ... your percentage full is 0.000
For your disk drive = /system/contract ... your percentage full is 0.000
For your disk drive = /proc ... your percentage full is 0.000
For your disk drive = /etc/mnttab ... your percentage full is 0.000
For your disk drive = /etc/svc/volatile ... your percentage full is 1.000
For your disk drive = /system/object ... your percentage full is 0.000
For your disk drive = /dev/fd ... your percentage full is 0.000
For your disk drive = /var/run ... your percentage full is 1.000
For your disk drive = /s01 ... your percentage full is 50.000
For your disk drive = /s02 ... your percentage full is 40.000
For your disk drive = /u01 ... your percentage full is 20.000
For your disk drive = ... your percentage full is 0.000
This is wonderful! My background is in VMS scripting, and I've been looking for a Korn equivalent to DCL F$FAO for a long time. This is the closest I've seen.
Thanks for the snippet of code. I have what I need now.
Apparently, numb is a string. Can you tell me how convert it to integer and subtract it from 100? That would let me display the output as % free, rather than % full.