常用 shell 脚本

记录常用 shell 脚本。

id.sh

1
echo $(sudo lsof -i:7091|grep main|awk 'NR==1{print $2}')

start.sh

1
2
sudo nohup go run ./main.go >> web.log 2>&1 &
echo $(sudo lsof -i:7091|grep main|awk 'NR==1{print $2}')

stop.sh

1
2
3
4
5
6
7
8
9
# 先过滤出 7091 端口,用 grep 过滤出 main,同时用 awk 过滤出第二行的数据
id=$(sudo lsof -i:7091|grep main|awk 'NR==1{print $2}')
if [ ! ${id} ]
then
  echo "项目未启动!"
else
  kill -9 $id
  echo "项目已关闭!"
fi

restart.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
id=$(sudo lsof -i:7091|grep main|awk 'NR==1{print $2}')
if [ ! ${id} ]
then
  echo "项目未启动!"
else
  sudo kill -9 $id
  echo "项目已关闭!"
fi
sudo chmod +x ./main
sudo nohup ./main >> web.log 2>&1 &
echo $(sudo lsof -i:7091|grep main|awk 'NR==1{print $2}')

egg-server.sh

1
2
3
4
5
6
7
cd /opt/egg-server;
pid=$(ps -ef | grep "egg" | grep -v grep | awk '{print $2}' |tail -n 3 | head -n 1);
kill ${pid}
sudo git pull origin master
sudo npm i
nohup npm run dev &
exit 0
Licensed under CC BY-NC-SA 4.0