擅长:python、mysql、java
<p>首先为名为tg.sh的电报创建<a href="https://www.zabbix.com/forum/showthread.php?t=45600" rel="noreferrer">bash script</a>:</p>
<pre><code>#!/bin/bash
now=$(date)
to=$1
subject=$2
body=$3
tgpath=/home/youruser/tg
LOGFILE="/home/youruser/tg.log"
cd ${tgpath}
${tgpath}/telegram -k ${tgpath}/tg-server.pub -W <<EOF
msg $to $subject
safe_quit
EOF
echo "$now Recipient=$to Message=$subject" >> ${LOGFILE}
echo "Finished" >> ${LOGFILE}
</code></pre>
<p>然后将脚本放在与python脚本相同的文件夹中,并使用<code>chmod +x tg.sh</code>授予它+x权限</p>
<p>最后,从python中,您可以执行以下操作:</p>
<pre><code>import subprocess
subprocess.call(["./tg.sh", "user#****", "message here"])
</code></pre>