0
我不明白爲什麼我的'for循環'無法正常工作。第一個參數正常工作。如果我手動停用第二個Python腳本,它將不會再次啓動腳本。你能幫我嗎?重新激活python腳本 - Linux bash腳本
#!/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