У меня есть действительно простой сценарий bash, который каждую минуту запускается как задание cron. Делает журнал в файл. Все работает нормально, но есть одна странность. Скрипт одновременно ведет несколько журналов. Я не понимаю, как это возможно. Вот код.
#!/bin/bash
# -c returns number of lines in grep result
isActive=$(systemctl status elasticsearch | grep "active (running)" -c)
if (( $isActive == 0 ))
then
systemctl start elasticsearch
timestamp=$(date +"%Y-%m-%d %H-%M-%S")
touch /root/custom-scripts/elasticsearch/start.log
echo "${timestamp} Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active." >> /root/custom-scripts/elasticsearch/start.log
fi
Задание cron
* * * * * bash /root/custom-scripts/elasticsearch/start-elasticsearch.sh
Файл журнала выглядит так:
2021-07-13 16-17-45 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-17-45 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-17-45 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-17-45 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-20-15 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-20-15 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-20-15 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-23-11 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-26-36 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-26-36 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-26-36 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-33-13 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-33-13 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-33-13 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-33-13 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-33-25 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-34-10 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-35-10 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-40-39 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-40-39 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-40-39 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-40-39 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-40-39 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-41-13 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
2021-07-13 16-42-07 Elasticsearch service has to be restarted by /root/custom-scripts/elasticsearch/start-elasticsearch.sh because service status was not active.
Есть ли кто-нибудь, кто может мне это объяснить? Большое спасибо.
Я бы проверил пару вещей: