Skip to content

Instantly share code, notes, and snippets.

@lazydao
Last active September 1, 2025 02:20
Show Gist options
  • Select an option

  • Save lazydao/41c05502a431f1f6415215bc41716888 to your computer and use it in GitHub Desktop.

Select an option

Save lazydao/41c05502a431f1f6415215bc41716888 to your computer and use it in GitHub Desktop.
Linux
# 用淘宝源下载python包进行安装
v=$1
wget https://npm.taobao.org/mirrors/python/$v/Python-$v.tar.xz -P ~/.pyenv/cache/
pyenv install $v
# 如果存在目录则清空
test -d $log_dir && rm -rf $log_dir/*
# 如果不存在目录则创建
test ! -d $log_dir && mkdir $log_dir
# 查看端口占用
netstat -tunlp | grep 端口号
lsof -i:端口号
# 启动脚本至后台,记录pid
nohup python3 -u main.py & echo $! > pidfile
# 重启脚本并备份log
kill -2 `cat pidfile`
test ! -d log && mkdir log
baklog=log/`date +'%Y-%m-%d-%H-%M-%S'`.log
mv nohup.out $baklog
nohup python3 -u main.py & echo $! > pidfile
# 过滤日志并捕获前后N行内容
grep -i -C 5 "trace" error.log > output.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment