script shell send telegram msg with expect

First read this post for install and configure telegram

Create a new script named sendtg:

#!/usr/bin/expect
set timeout 2
set msg [lindex $argv 1]
set dest [lindex $argv 0]
spawn telegram -k /etc/telegram/server.pub -c /etc/telegram/telegram-cli/config -W
expect "> "
sleep 10
send "\rmsg $dest $msg\r"
expect "> "
expect eof

Config

move the script in /usr/bin:
mv sendtg /usr/bin/sendtg

and set correct permission:
chmod +x /usr/bin/sendtg

Usage

sendtg User “message to send”

2 thoughts on “script shell send telegram msg with expect

Leave a Reply

Your email address will not be published. Required fields are marked *