MrEfendi

Untitled

Jul 4th, 2019
39
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # PL:Skrypt kontrolujacy stan tmpfs
  4. # EN:Script for control tmpfs status
  5.  
  6. # http://filipczyk.net/optymalizacja-prestashop-16-cache-przyspieszenie/
  7. # 2014 - Filipczyk.net
  8.  
  9. # Configration:
  10.  
  11. source_to_prestashop="/home/www/public_html"#Zmien ścieżkę do presty
  12. security_procentage=90
  13. check_cachefs="yes"
  14. check_smarty_compile="yes"
  15. check_smarty_cache="yes"
  16. check_pagespeed="yes"
  17.  
  18. # Functions:
  19.  
  20. # check
  21.  
  22. function check {
  23. check_source $source_to_prestashop
  24. check_procentage $security_procentage
  25. check_check $check_cachefs
  26. check_check $check_smarty_compile
  27. check_check $check_smarty_cache
  28. check_check $check_pagespeed
  29. }
  30.  
  31. function check_source {
  32. if [ ! -d "$1" ]; then
  33. echo "Error: $1 - Doesn't exists"
  34. exit
  35. fi
  36. }
  37.  
  38. function check_procentage {
  39. check_max=100
  40. check_min=0
  41. if (("$1" > "$check_max")); then
  42. echo "Error: $1 - is wrong"
  43. exit
  44. fi
  45. if (("$1" < "$check_min")); then
  46. echo "Error: $1 - is wrong"
  47. exit
  48. fi
  49. }
  50.  
  51. function check_check {
  52. if [[ "$1" != "yes" && "$1" != "no" ]]; then
  53. echo "Error: $1 - is wrong. Use yes or no"
  54. exit
  55. fi
  56. }
  57.  
  58. # Controller
  59.  
  60. function event_do {
  61. state="good"
  62. event="nothing to do"
  63. if (("$1" >= "$security_procentage")); then
  64. state="bad"
  65. event="CLEARED!"
  66. source_to_remove="$source_to_prestashop$2/*"
  67. rm -rf $source_to_remove
  68. fi
  69. echo "#$2 -> $1%/100% = $state, $event"
  70. }
  71.  
  72. function controller {
  73. echo "tmpfs - Controler - $(date)"
  74. check
  75.  
  76. if [ "$check_cachefs" = "yes" ]; then
  77. status=`df -h $source_to_prestashop/cache/cachefs/ | awk '{print $5}' | tail -1 | sed 's/[^0-9]*//g'`
  78. name="/cache/cachefs"
  79. event_do $status $name
  80. fi
  81. if [ "$check_smarty_compile" = "yes" ]; then
  82. status=`df -h $source_to_prestashop/cache/smarty/compile/ | awk '{print $5}' | tail -1 | sed 's/[^0-9]*//g'`
  83. name="/cache/smarty/compile"
  84. event_do $status $name
  85. fi
  86. if [ "$check_smarty_cache" = "yes" ]; then
  87. status=`df -h $source_to_prestashop/cache/smarty/cache/ | awk '{print $5}' | tail -1 | sed 's/[^0-9]*//g'`
  88. name="/cache/smarty/cache"
  89. event_do $status $name
  90. fi
  91. if [ "$check_pagespeed" = "yes" ]; then
  92. status=`df -h $source_to_prestashop/cache/pagespeed/ | awk '{print $5}' | tail -1 | sed 's/[^0-9]*//g'`
  93. name="/cache/pagespeed"
  94. event_do $status $name
  95. fi
  96. }
  97.  
  98. # Execution code:
  99. controller
RAW Paste Data