File system capacity meter in shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File system capacity meter in shell
# 1  
Old 06-19-2010
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
# 2  
Old 06-19-2010
Code:
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" " " " "
}

This User Gave Thanks to cfajohnson For This Post:
# 3  
Old 06-19-2010
it works perfectly, many thanks
# 4  
Old 06-24-2010
the provided code is not working under ksh . is there any way to run into ksh script !!?
# 5  
Old 06-24-2010
Quote:
Originally Posted by bejo4ever
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.)
# 6  
Old 06-24-2010
im trying to merge the code with the below script

Code:
#!/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

Moderator's Comments:
Mod Comment Please use code tags, and indent your code

Last edited by Scott; 06-24-2010 at 06:12 PM.. Reason: Code tags
# 7  
Old 06-24-2010

Please answer all the questions I asked in my previous post.
Quote:
Originally Posted by bejo4ever
im trying to merge the code with the below script

Code:
#!/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


UUOC * 6 + UUOAwk * 5
Code:
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

Quote:
Code:
arr_set(){
  file_name='host_srvs'$1''


Why all those apostrophes?
Code:
file_name=host_srvs$1

Quote:
Code:
  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`


Why are you using expr? ksh can do integer arithmetic:
Code:
k=$(( $k + 1 ))

Quote:
Code:
  done < ${file_name}
}


Code:
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"
}

Quote:
Code:
arr_set 1  
arr_set 2
arr_set 3
arr_set 4
arr_set 5
arr_set 6

Code:
for n in 1 2 3 4 5 6
do
  arr_set "$n"
done

Quote:
Code:
##########################
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


What's the point of using if? The code is the same in both branches.
Quote:
Code:
  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 `


See above; expr is not necessary
Quote:
Code:
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

Moderator's Comments:
Mod Comment Please use code tags, and indent your code

Where have you merged the code I provided?

Perhaps you should put it into a function?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. OS X (Apple)

Text mode dual _LED_ VU meter.

Hi guys... Finally decided to release this, I have a python version too but that is unimportant to me. It is a text mode "Dual_VU.sh" meter. It actually calls dash as the interpreter but change the shebang to suit yourselves. It uses the bell character for overload per channel and... (1 Reply)
Discussion started by: wisecracker
1 Replies

2. Homework & Coursework Questions

Disk Capacity Shell Script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! I am pretty close I think, but stuck. I don't know how to send an email to the user specified on the command line, and I receive an error stating -ge expecting a unary value(lines... (14 Replies)
Discussion started by: polyglot0727
14 Replies

3. Shell Programming and Scripting

Help with a shell script to check /var file system

deleting (0 Replies)
Discussion started by: fretagi
0 Replies

4. Shell Programming and Scripting

Running remote system shell script and c binary file from windows machine using java

Hi, I have an shell script program in a remote linux machine which will do some specific monitoring functionality. Also, have some C executables in that machine. From a windows machine, I want to run the shell script program (If possible using java). I tried with SSH for this. but, in... (1 Reply)
Discussion started by: ram.sj
1 Replies

5. Shell Programming and Scripting

Shell script to find filesystem capacity on 50 servers

Hi all, I am new to Unix and I want to write a shell script in a jumpbox for finding the filesystem capacity on 50 unix servers ( by ssh ) and then email the result in HTML format with server name and capacity % to a specific outlook distribution list. any suggestion would be of great help. (17 Replies)
Discussion started by: amitbisht9
17 Replies

6. Shell Programming and Scripting

Shell Script for monitoring File system.

Hi, need help to write one shell script to monitor UNIX file systems and if any changes happend like deletion of any file, adding new file, time stamp changed, permisson changed etc. Script need to send alert mail to defined person/mail id. I request someone to help me to create the... (1 Reply)
Discussion started by: vjauhari
1 Replies

7. UNIX for Dummies Questions & Answers

File Size Capacity

How to view file size limit in unix.. From my case is when the file size over 80% full is has to be an alert. Thank you (3 Replies)
Discussion started by: tanjonathan
3 Replies

8. Shell Programming and Scripting

File System Check using shell script !!!

Hi Guys I m posing this new thread as I didnt get satisfactory result after running search here. My requirement is very simple (using shell script) I need to findout what all file systems are mounted -> Then I need check the health of that file system - by disk usage & by doing a simple... (8 Replies)
Discussion started by: csaha
8 Replies

9. UNIX for Dummies Questions & Answers

how to mount a file system of a remote machine to local file system

Hi friends, In my case, there are serveral PCs running Linux in a LAN. I would like to to mount the directory /A_river of machine-A to the file system of another machine machine-B so that I can access files in that directory. I do not know how to do this. The situation is complicated by... (2 Replies)
Discussion started by: cy163
2 Replies
Login or Register to Ask a Question