有时候我们经常要结束占用某些端口的程序。就会需要以下脚本:
以下是redis的
#!/bin/bash
port=6379
name=$(lsof -i:$port|tail -1|awk '"$1"!=""{print $2}')
if [ -z $name ]
then
echo "No process can be used to killed!"
exit 0
fi
id=$(lsof -i:$port|tail -1|awk '"$1"!=""{print $2}')
kill -9 $id
echo "Process name=$name($id) kill!"
exit 0