port-squid.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. sqd="$(cat /etc/squid/squid.conf | grep -i http_port | awk '{print $2}' | head -n1)"
  3. sqd2="$(cat /etc/squid/squid.conf | grep -i http_port | awk '{print $2}' | tail -n1)"
  4. echo -e "======================================"
  5. echo -e ""
  6. echo -e " [1] Change Port $sqd"
  7. echo -e " [2] Change Port $sqd2"
  8. echo -e " [x] Exit"
  9. echo -e "======================================"
  10. echo -e ""
  11. read -p " Select From Options [1-2 or x] : " prot
  12. echo -e ""
  13. case $prot in
  14. 1)
  15. read -p "New Port Squid: " squid
  16. if [ -z $squid ]; then
  17. echo "Please Input Port"
  18. exit 0
  19. fi
  20. cek=$(netstat -nutlp | grep -w $squid)
  21. if [[ -z $cek ]]; then
  22. sed -i "s/$sqd/$squid/g" /etc/squid/squid.conf
  23. sed -i "s/$sqd/$squid/g" /root/log-install.txt
  24. /etc/init.d/squid restart > /dev/null
  25. echo -e "\e[032;1mPort $squid modified successfully\e[0m"
  26. else
  27. echo "Port $squid is used"
  28. fi
  29. ;;
  30. 2)
  31. read -p "New Port Squid: " squid
  32. if [ -z $squid ]; then
  33. echo "Please Input Port"
  34. exit 0
  35. fi
  36. cek=$(netstat -nutlp | grep -w $squid)
  37. if [[ -z $cek ]]; then
  38. sed -i "s/$sqd2/$squid/g" /etc/squid/squid.conf
  39. sed -i "s/$sqd2/$squid/g" /root/log-install.txt
  40. /etc/init.d/squid restart > /dev/null
  41. echo -e "\e[032;1mPort $squid modified successfully\e[0m"
  42. else
  43. echo "Port $squid is used"
  44. fi
  45. ;;
  46. x)
  47. exit
  48. menu
  49. ;;
  50. *)
  51. echo "Please enter an correct number"
  52. ;;
  53. esac