I'm working on a script where I monitor the reading and calculation of some data, after executing this script I would like to print the output and send it directly to a telegram channel, but for that I need to execute a command after the awk output.
Messages are arriving on telegram, but they are arriving incomplete (only the first line, in total there are 4 lines per message)
Original output from AWK:
#Price_Notification_ProductABC Price: 0.007023 change: +1.8% Count Number: 6
Exit that is coming on telegram:
#Price_Notification_ProductABC
Could you help me to solve what is wrong? Thanks
Here are my scripts:
awk.sh
#!/bin/bash
awk '
/^#Price_Notification_Product/ {
prod = $0;
}
/^change: / {
gsub(/[+%]/,"",$2);
products[prod] += $2;
$2 = "+" products[prod] "%"
}
1' input.txt | xargs -l ./telegram-send.sh
telegram-send.sh
#!/bin/bash
GROUP_ID=-myid
BOT_TOKEN=mytoken
# this 3 checks (if) are not necessary but should be convenient
if [ "$1" == "-h" ]; then
echo "Usage: `basename $0` \"text message\""
exit 0
fi
if [ -z "$1" ]
then
echo "Add message text as second arguments"
exit 0
fi
if [ "$#" -ne 1 ]; then
echo "You can pass only one argument. For string with spaces put it on quotes"
exit 0
fi
curl -s --data "text=$1" --data "chat_id=$GROUP_ID" 'https://api.telegram.org/bot'$BOT_TOKEN'/sendMessage' > /dev/null