Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Uses telegram-cli to send a message to the given destination
- # Usage: ./telegram_msg <DESTINATION> <MESSAGE>
- #==============================================================
- # Constants
- #==============================================================
- APP_NAME=telegram_msg
- # Name of the app as appears in logs
- APP="/usr/local/bin/telegram-cli"
- # telegram-cli location
- PUBKEY="/opt/telegram-cli/tg-server.pub"
- INIT_TIME=0.5
- # Time telegram-cli bootstraps including retrieving
- # contacts
- #==============================================================
- # Arguments
- #==============================================================
- DESTINATION=$1
- MESSAGE=$2
- shift
- #==============================================================
- # Code
- #==============================================================
- #--------------------------------------------------------------
- # 1. Check arguments
- #--------------------------------------------------------------
- # Destination
- if [[ -z "$DESTINATION" ]]; then
- >&2 echo "Destination not set"
- logger -t $APP_NAME "Failed to send: Destination unset"
- exit 1
- fi
- # Message
- if [[ -z "$MESSAGE" ]]; then
- >&2 echo "Message not set"
- logger -t $APP_NAME "Failed to send: Message unset"
- exit 2
- fi
- # Join messages
- # # Make temporal file with all messages
- tmp_file=$(mktemp)
- while (( "$#" )); do
- echo "$1" >> $tmp_file
- shift
- done
- #--------------------------------------------------------------
- # 2. Send
- #--------------------------------------------------------------
- ((sleep $INIT_TIME && echo send_text $DESTINATION $tmp_file) | \
- $APP -k $PUBKEY -W) # &> /dev/null
- # Log
- logger -t $APP_NAME "Sent message via Telegram @ bitcoin"
- # Delete temporaries and finish
- rm $tmp_file
- echo "$USER sent a message via Telegram"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement