Answer the question
In order to leave comments, you need to log in
Criticize the bash script?
I am very far from scripts and development. It took some time to make a simple script. Check, pliz, who does not complicate. The script works. Threw it into fcron for execution once a minute. But sometimes messages in telegrams fall with a delay of 3 to 20 minutes.
#!/bin/bash
KEY="xxxxxxx:yyyyyyyyyyy" #ключ телегграм-бота
TARGET="-4343905834509345098345" #id группы телеграм
URL1="https://api.telegram.org/bot$KEY/sendMessage"
output=$(curl -s 'https://экзампл.ком/api/posts/json')
OLD_TIME=$(echo $(cat /root/telegram/previous_post_time.json)) #время создания предыдущего поста, записанного в epoch-time.
GET_TIME=$(echo $output | jq .posts[0].created) #вытаскиваем из запроса время создания последнего поста
if (( $GET_TIME > $OLD_TIME )); then
TIME=$(echo $GET_TIME>/root/telegram/previous_post_time.json) #записываем новое значение времени создания поста.
GET_URL=$(echo $output | jq -r .posts[0]._links[1].href)
GET_USER=$(echo $output | jq -r .posts[0].user.login)
URL=$(echo $GET_URL>/root/telegram/url.json)
TEXT="$GET_USER $GET_URL"
PAYLOAD="chat_id=$TARGET&text=$TEXT&parse_mode=Markdown"
curl -s --max-time 10 --retry 5 --retry-delay 2 --retry-max-time 10 -d "$PAYLOAD" $URL1 > /dev/null 2>&1 &
else
exit 0
fi
exit 0
Answer the question
In order to leave comments, you need to log in
if (( $GET_TIME > $OLD_TIME )); then
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question