重新激活python脚本 - Linux bash脚本

时间:2017-10-07 14:51:04

标签: linux bash shell

我不明白为什么我的循环'没有正常工作。第一个论点很好。如果我手动停用第二个python脚本,它将无法再次启动脚本。你能帮助我吗?

#!/bin/bash
cd /home/admin/instaTweet

bots=( one.py two.py three.py )
botSize=${#bots[*]}
checkProcessSize=$(ps -e -o comm= | grep screen | wc -l)


echo $(date) >> checkBotsLog.txt
echo "$botSize Bots available" >> checkBotsLog.txt

if [ $botSize -gt $checkProcessSize ]
then
        time=$(date)
        tweet_string="###ALERT### At least one bot is inactive! "$(echo $time)
        python3 tweet.py "$(echo $tweet_string)"
        echo "At least one Bot is inactive" >> checkBotsLog.txt

        for i in $bots; do
                process=$(ps -aux | grep "python $i" | wc -l)

                if [ $process -lt 2 ]
                then
                        screen -d -m python $i
                        echo $i started >>checkBotsLog.txt
                fi
        done
else
        time=$(date)
        tweet_string="All bots are active! "$(echo $time)
        python3 tweet.py "$(echo $tweet_string)"
        echo "Everything fine" >> checkBotsLog.txt
fi

1 个答案:

答案 0 :(得分:0)

好的,我刚想通了。

我改变了:

-a, --append
       append to the given FILEs, do not overwrite

为:

for i in $bots; do...