crontab执行shell脚本

shell 脚本如下

#!/bin/sh
source /etc/profile #需要导入环境变量,否则非原生命令执行不成功

procs=`ps -ef | grep python | grep aiphoto_data_maintain/bin/aiphoto_data | awk '{print $2}'`
for p in ${procs[@]}
do
    if [ "$p" != "" ]; then
        echo "kill $p"
        kill $p
    fi
done
sleep 3



echo "restarting ..."
#nohup python -u ai_photo/aiphoto_run.py -e Local -s https://aiphoto-test.howfun.tv -p 23288 > nohup.out 2>&1 &

ai_photo_data="/data2/yingjie/aiphoto_data_maintain/ai_photo_data_nohup.out"

if [ -f "$ai_photo_data" ]; then
rm "$ai_photo_data"
echo "remove log ..."
fi

nohup /data2/yingjie/aiphoto_data_maintain/venv/bin/python /data2/yingjie/aiphoto_data_maintain/bin/aiphoto_data.py > "$ai_photo_data" 2>&1 &
echo "aiphoto mongo success ..."



procs=`ps -ef | grep python | grep aiphoto_data_maintain/bin/photo_data | awk '{print $2}'`
for p in ${procs[@]}
do
    if [ "$p" != "" ]; then
        echo "kill $p"
        kill $p
    fi
done
sleep 3


photo_data="/data2/yingjie/aiphoto_data_maintain/photo_data_nohup.out"

if [ -f "$photo_data" ]; then
rm "$photo_data"
echo "remove log ..."
fi

nohup /data2/yingjie/aiphoto_data_maintain/venv/bin/python /data2/yingjie/aiphoto_data_maintain/bin/photo_data.py > "$photo_data" 2>&1 &
echo "photo_data mongo success ..."

 

crontab 命令

08 13  * * * /bin/bash  /data2/yingjie/aiphoto_data_maintain/bin/back_mongo.sh

 

 

 

 

 

posted on 2022-12-14 13:10  星河赵  阅读(965)  评论(0编辑  收藏  举报

导航