<分区>
我不明白为什么我的“for 循环”不能正常工作。第一个参数工作正常。如果我手动停用第二个 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