File system capacity meter in shell

HI

i need help to show the file system capacity in meter or like the progress bar .

OS = Solaris 10

df "$1" | { 
read; read fs blocks used avail usedpc mount
pc=$(( ${usedpc%\%} * 60 / 100 ))
echo $pc
rem=$(( 57 - $pc ))
printf "|\e[41m%${pc}s\e[0m%${rem}s|\n" " " " "
}
1 Like

it works perfectly, many thanks

the provided code is not working under ksh . is there any way to run into ksh script !!?

What does "not working" mean? What does happen?

Did you run the code exactly as posted? If not, what did you change?

What terminal emulator are you using?

What version of ksh are you using?

(It works for me with ksh93 and pdksh.)

im trying to merge the code with the below script

#!/usr/bin/ksh
clear
echo
echo
echo "\t\t\t\t                   **** Critical File system at : `date` **** "
echo
echo "                                            Hostname              Owner        Capacity         Free Space        Path " 
echo "                                        ----------------------------------------------------------------------------------------------------"

cat  crtl_fs |awk -F\t '{print $1}' >host_srvs1
cat  crtl_fs |awk -F\t '{print $2}' >host_srvs2
cat  crtl_fs |awk -F\t '{print $3}' >host_srvs3
cat  crtl_fs |awk -F\t '{print $4}' >host_srvs4
cat  crtl_fs |awk -F\t '{print $5}' >host_srvs5
cat  crtl_fs |awk -F\t '{print $6}' >host_srvs6

arr_set(){
file_name='host_srvs'$1''
k=0
while read file_line
do
f=$1
if [ $f -eq 1 ]
then
arry1[$k]=${file_line}
fi
if [ $f -eq 2 ]
then
arry2[$k]=${file_line}
fi
if [ $f -eq 3 ]
then
arry3[$k]=${file_line}
fi
if [ $f -eq 4 ]
then
arry4[$k]=${file_line}
fi
if [ $f -eq 5 ]
then
arry5[$k]=${file_line}
fi
if [ $f -eq 6 ]
then
arry6[$k]=${file_line}
fi
k=`expr $k + 1`
done < ${file_name}
}
arr_set 1  
arr_set 2
arr_set 3
arr_set 4
arr_set 5
arr_set 6
##########################
RED="echo \\033[0;31m\c"
NORMAL="echo  \\033[0;39m"
GREEN="echo  \\033[0;32m\c"
BLUE="echo \\033[0;35m\c" 
n=0
while [ $n -lt $k ]
do
i=${arry3[$n]}
sun=`echo "${arry1[$n]}" |awk '{print $1}'`
if [ "$sun" == "Sun" -o $sun == "TABS" ]
then 
is=`rsh ${arry2[$n]} 2>/dev/null df -k $i | awk '{print $5}' | cut -f1 -d% | grep -v capacity`
else
is=`rsh ${arry2[$n]} 2>/dev/null df -k $i | awk '{print $5}' | cut -f1 -d% | grep -v capacity`
fi
if [ "$is" -ge "${arry6[$n]}"  ]
                        then
                                $RED
echo "\t\t\t\t\t\t  ${arry2[$n]}\t\t${arry1[$n]}\t\t$is %\t\t`rsh ${arry2[$n]} 2>/dev/null df -h $i | awk '{print $4}' | cut -f1 -dG | grep -v avail` "GB"\t\t$i \c"
                                $NORMAL
fi

n=`expr $n + 1 `
done 
echo
rm  host_srvs1 host_srvs2 host_srvs3 host_srvs4 host_srvs5 host_srvs6 2>/dev/null
echo  "\n\t\t\t\t\t\t\t  ****  Press \"Enter To \"  Quit ****"
read a

KSH Version M-11/16/88i

Please answer all the questions I asked in my previous post.

UUOC * 6 + UUOAwk * 5

awk -F '\t' {
print $1 > "host_srvs1"
print $2 > "host_srvs2"
print $3 > "host_srvs3"
print $4 > "host_srvs4"
print $5 > "host_srvs5"
print $6 > "host_srvs6"
}'  crtl_fs

Why all those apostrophes?

file_name=host_srvs$1

Why are you using expr? ksh can do integer arithmetic:

k=$(( $k + 1 ))
arr_set(){
  file_name=host_srvs$1
  k=0
  while read file_line
  do
    f=$1
    eval "arry$f[$k]=\$file_line"
  done < "$file_name"
}
for n in 1 2 3 4 5 6
do
  arr_set "$n"
done

What's the point of using if? The code is the same in both branches.

See above; expr is not necessary

Where have you merged the code I provided?

Perhaps you should put it into a function?

Thanks for your prompt reply, first of all let me tell you crtl_fs file content many servers and file systems :

DBA     xxxxxx        /xxxx/xxxxx      80      85      90

1st column is to figure out which team this file system is belong to
2nd = HOSTNAME
3rd = file system path
4,5 and 6 file system thresholds

the main script should operate all file systems exceeded the last threshold ( column 6).

yes

Xshell

KSH Version M-11/16/88i
OS and server Details = SunOS 5.10 Generic_142900-05 sun4u sparc SUNW,Sun-Fire-V490

to know if the file system exceeded the threshold or not .

i executed as received in the ksh shell and i got the below and not colored

27
|\e[41m                           \e[0m                              |

into the echo

The code is the same in both branches, so you are not checking anything; you can just remove the if, then, else and fi and leave

is=`rsh ${arry2[$n]} 2>/dev/null df -k $i | awk '{print $5}' | cut -f1 -d% | grep -v capacity`

In an earlier post, you said the code I supplied worked. Obviously you have changed something.

That something may be the echo, which I didn't use; echo is not the same as printf.