1.linux杀掉某个进程

vim kills.sh

#!/bin/sh

NAME=$1   # $1 运行时输入参数  为文件名称
#NAME="run_video.py"   # 指定进程
echo $NAME
ID=`ps -ef | grep "$NAME" | grep -v "$0" | grep -v "grep" | awk '{print $2}'`
echo $ID
echo "---------------"
for id in $ID
do
kill -9 $id
echo "killed $id"
done
echo "---------------"


bash kills.sh test.py

# 查看日志
cd /root/02-game/01-steam/steam_video/steam_video && tail -f nohup.out
cd /root/02-game/01-steam/steam_video/steam_video && nohup python3.6 run_video.py

2.定时重新启动某个进程

vim /root/video.sh

#!/bin/bash
NAME="videos"   # 指定进程
echo $NAME
ID=`ps -ef | grep "$NAME" | grep -v "$0" | grep -v "grep" | awk '{print $2}'`
echo $ID
echo "---------------"
for id in $ID
do
kill -9 $id
echo "killed $id"
done
echo "---------------"

export PATH=$PATH://usr/local/python3.6/bin
cd /root/07-shunwangwork/01-steam/steam_video/steam_video
scrapy crawl videos


*/1 * * * * /bin/bash /root/video.sh
/sbin/service crond restart //重启服务

3.判断某个进程 

vim /root/video.sh

#!/bin/bash
tmp=`ps -ef |grep video |grep -v grep |wc -l`
if [ $tmp -eq 0 ];then
export PATH=$PATH://usr/local/python3.6/bin
cd /root/07-shunwangwork/01-steam/steam_video/steam_video
scrapy crawl videos
fi


*/1 * * * * /bin/bash /root/video.sh
/sbin/service crond restart //重启服务

4.启动某个python文件

vim /root/run_video.sh

#!/bin/sh
NAME=$1  # $1 运行时输入参数  为文件名称
NAME=${NAME%%.*}
if [ -z "$NAME" ]; then
 echo "STRING is empty"
 NAME="aa"
fi
echo $NAME
ID=`ps -ef | grep "$NAME" | grep -v "$0" | grep -v "grep" | awk '{print $2}'`
echo $ID
echo "---------------"
for id in $ID
do
kill -9 $id
echo "killed $id"
done
echo "---------------"

sleep 1

current_dir=$(cd $(dirname $0); pwd)

echo $current_dir
if [ ! -d "$current_dir/logs" ]; then
    echo "$current_dir/logs does not exist"
    `mkdir $current_dir/logs`
fi

echo "---------------"
echo "nohup /usr/bin/python3.6 $current_dir/$NAME.py > $current_dir/logs/$NAME.log 2>&1 &"
echo "---------------"
echo "tail -f $current_dir/logs/$NAME.log"

`nohup /usr/bin/python3.6 $current_dir/$NAME.py > $current_dir/logs/$NAME.log 2>&1 &`

echo "启动成功"



bash /root/run_video.sh  test.py