您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. #
  3. # z3bra - (c) wtfpl 2014
  4. usage () {
  5. cat <<EOF
  6. usage: $(basename $0) [-hptu]
  7. -h : print help
  8. -p : percentage of memory used (default)
  9. -t : total available memory
  10. -u : memory used (human-readable)
  11. EOF
  12. }
  13. # display the total of available memory in human readable format
  14. memtotal () {
  15. read mem <<< `grep -E 'MemTotal' /proc/meminfo |awk '{print $2}'`
  16. if [ $mem -gt 1048576 ]; then
  17. mem=`bc <<< "scale=2; $mem / 1048576"`
  18. mem="${mem}G"
  19. elif [ $mem -gt 1024 ]; then
  20. mem=`bc <<< "$mem / 1024"`
  21. mem="${mem}M"
  22. fi
  23. echo $mem
  24. }
  25. # display the memory used in human readable format
  26. memused () {
  27. read t f <<< `grep -E 'Mem(Total|Free)' /proc/meminfo |awk '{print $2}'`
  28. read b c <<< `grep -E '^(Buffers|Cached)' /proc/meminfo |awk '{print $2}'`
  29. mem=`bc <<< "($t - $f - $c - $b)"`
  30. if [ $mem -gt 1048576 ]; then
  31. mem=`bc <<< "scale=2; $mem / 1048576"`
  32. mem="${mem}G"
  33. elif [ $mem -gt 1024 ]; then
  34. mem=`bc <<< "$mem / 1024"`
  35. mem="${mem}M"
  36. fi
  37. echo $mem
  38. }
  39. # display the memory used in percentage
  40. memperc () {
  41. read t f <<< `grep -E 'Mem(Total|Free)' /proc/meminfo |awk '{print $2}'`
  42. read b c <<< `grep -E '^(Buffers|Cached)' /proc/meminfo |awk '{print $2}'`
  43. mem=`bc <<< "100 * ($t - $f - $c - $b) / $t"`
  44. echo "${mem}%"
  45. }
  46. case $1 in
  47. -h) usage;;
  48. -t) memtotal;;
  49. -u) memused;;
  50. *) memperc;;
  51. esac