18.118.227.69 |    

Navigation

Google Advertisement

This script dispaly the disk space of a lokal or remote host.

volume
  1. #!/bin/bash
  2. # *************************************************************
  3. # file: volume
  4. # version: 1.01
  5. # date: 2005-05-19
  6. # author: Marko Schulz - <info@tuxnet24.de>
  7. # description: dispaly the disk space of a lokal or remote host
  8. # *************************************************************
  9.  
  10. # width of bars...
  11. FORMAT="30"
  12.  
  13. # *************************************************************
  14. # create bars...
  15.  
  16. function getbar() {
  17.  
  18. local i=0
  19. local count=$1
  20. local space=${2:-' '}
  21. while [ $i -le $count ]; do
  22. 	str="${str}${space}"
  23. 	i=$(( $i + 1))
  24. done
  25. echo "$str"
  26.  
  27. }
  28.  
  29. # *************************************************************
  30. # calculate relationship between used and free disk space...
  31.  
  32. function calculate() {
  33.  
  34. local used=$1
  35. local free=$2
  36. local width=$3
  37. used=$( perl -e "printf \"%.0f\", ( $free*$width/100 );" )
  38. free=$[$width - $used]
  39. echo -n "$free:$used"
  40.  
  41. }
  42.  
  43. # *************************************************************
  44. # show help...
  45.  
  46. function help() {
  47.  
  48. header
  49. echo
  50. echo -e "Usage: $( basename $0 ) [-r <user>@<host> -F integer -m {text|color} -h -s ]\n"
  51. echo -e "\t-r display the disk space from remote host"
  52. echo -e "\t-F width of the dispay"
  53. echo -e "\t-m output modus {text|color}"
  54. echo -e "\t-s to suppress header"
  55. echo -e "\t-h show this Help\n\a"
  56. exit 0
  57.  
  58. }
  59.  
  60. # *************************************************************
  61. # show header...
  62.  
  63. function header() {
  64.  
  65. echo "*********************************************************"
  66. echo -e "$( basename $0) v1.01 - display disk space of lokal or remote host"
  67. echo -e "Copyright (c) 2005 by Marko Schulz - <mschulz@jamba.net>"
  68. echo "*********************************************************"
  69.  
  70. }
  71.  
  72. # *************************************************************
  73. # P R O G R A M   A C T I O N
  74.  
  75. while getopts r:F:m:hs Optionen 2>/dev/null; do
  76. 	case $Optionen in
  77. 		r) REMOTE=$OPTARG ;;
  78. 		F) FORMAT=$OPTARG ;;
  79. 		m) MODUS=$OPTARG  ;;
  80. 		s) SUPPRESS="on"  ;;
  81. 		h) help ;;
  82. 	esac
  83. done
  84.  
  85. # Temporary file...
  86. temp="/tmp/$( basename $0 | sed 's/\.[a-z]\{2,\}$//g' )-$$.log"
  87.  
  88. # delete temporary file after finish...
  89. trap "[ -f $temp ] && rm $temp" EXIT
  90.  
  91. # get df-output from remote or lokal host...
  92. if [ -n "$REMOTE" ]; then
  93. 	ssh $REMOTE 'df -h' > $temp
  94. else
  95. 	df -h > $temp
  96. fi
  97.  
  98. # suppress header
  99. [ "$SUPPRESS" != "on" ] && header
  100.  
  101. echo
  102.  
  103. # loop data from temporary file...
  104. for result in $( cat $temp | grep '^/dev/' | awk '{ print $3":"$4":"$5":"$6 }' ); do
  105.  
  106. 	used=$( echo $result | cut -d: -f3 | sed 's/%//g' )
  107. 	sused=$( echo $result | cut -d: -f1 )
  108. 	sfree=$( echo $result | cut -d: -f2 )
  109. 	xused=$used
  110.  
  111. 	mount=$( echo $result | cut -d: -f4 )
  112.  
  113. 	free=$[100 - $used]
  114. 	xfree=$free
  115.  
  116. 	used=$( calculate $used $free $FORMAT | cut -d: -f1 )
  117. 	free=$( calculate $used $free $FORMAT | cut -d: -f2 )
  118.  
  119. 	if [ "$MODUS" = 'color' ]; then
  120.  
  121. 		used="$( getbar "$used" )"
  122. 		free="$( getbar "$free" )"
  123.  
  124. 		# Output...
  125. 		erg=$( printf "%5s %4s %29s %3s %4s %-35s\n" "$sused" "${xused}%" \
  126. 			"\033[41m${used}\033[0m\033[42m${free}\033[0m" "${xfree}%" "$sfree" "$mount" )
  127. 		echo -e "$erg"
  128.  
  129. 	else
  130.  
  131. 		used="$( getbar "$used" ':' )"
  132. 		free="$( getbar "$free" '.' )"
  133.  
  134. 		# Output...
  135. 		printf "%5s %4s %29s %3s %4s %-35s\n" "$sused" "${xused}%" \
  136. 			"${used}${free}" "${xfree}%" "$sfree" "$mount"
  137.  
  138. 	fi
  139.  
  140. 	echo
  141.  
  142. done
  143.  
  144. # *************************************************************
  145. # EOF
Parsed in 0.004 seconds at 873.42 KB/s

Search
 
Full text search by name and content of a snippet.

User online
There are 7 users online.

Tags Cloud

Latest snippets
str2seconds
(Bash::Function)
is_integer
(Bash::Function)
file_rotate
(Bash::Function)
confirm
(Bash::Function)
is_workingtime
(Bash::Function)
last day of last month
(Bash::Snippets)
crypt_apr1_md5
(PHP::Function)
crypt_apr1_md5
(Perl::Function)
transparent
(CSS)
rfc2822Toiso8601
(PHP::Function)