Loading

linux脚本编写记录

1.重启某个端口,适用于如tomcat重启8080端口,根据lsof命令查出,通过grep获取指定行,
awk获取到指定列进而得出pid值关闭即可.
pid=`lsof -i:3001|grep -v 'PID'|grep -w '(LISTEN)'|awk '{print $2}' `
echo $pid
if [ "$pid" != "" ];then
kill -9 $pid
echo "kill PID $pid successed!"
fi
 2.后台运行程序
nohup npm run start >run.log 2>&1 & 

exit

 3.shell脚本传值

sh testsh.sh  1 

testsh中通过 '$1' 取到参数,
$#是个数
$*显示所有的参数.

 

posted @ 2019-03-07 17:15  ichar  阅读(253)  评论(0编辑  收藏  举报