stop-port.sh 322 B

123456789101112131415161718
  1. #!/usr/bin/sh
  2. #echo $#
  3. if test $# -ne 1
  4. then
  5. echo Usage: stop-port.sh port
  6. echo Example: ./stop-port.sh 8081
  7. exit
  8. fi
  9. port=$1
  10. pid=`netstat -npa|grep LISTEN|grep $port|awk '{print $7}'|awk -F '/' '{print $1}'`
  11. if [ -z $pid ]
  12. then
  13. echo 'service not start!'
  14. else
  15. kill $pid
  16. echo $pid
  17. echo 'service is killed!'
  18. fi