我正在创建一个新的shell脚本crontab通知电报,但未收到消息
环境 ubuntu 16.04
uname -n >> text.txt
while read p; do
adb -s "$p" shell getprop ro.product.manufacturer >> text.txt
adb -s "$p" shell dumpsys battery | grep level >> text.txt
adb -s "$p" shell getprop ro.product.model >> text.txt
adb -s "$p" shell dumpsys battery | grep health >> text.txt
TEXT=$(cat text.txt)
curl -X POST https://api.telegram.org/bot<token>/sendMessage -d chat_id=<chat id> -d text="$TEXT"
rm text.txt
done <info.txt
我希望可以通过电报接收消息
此日志cron
cron.service - Regular background program processing daemon
Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2019-03-25 17:53:44 WIB; 11min ago
Docs: man:cron(8)
Main PID: 14599 (cron)
Tasks: 1
Memory: 3.3M
CPU: 229ms
CGroup: /system.slice/cron.service
└─14599 /usr/sbin/cron -f
Mar 25 18:02:01 -Latitude-3490 CRON[14811]: pam_unix(cron:session): session opened for user root by (uid=0)
Mar 25 18:02:01 -Latitude-3490 CRON[14812]: (root) CMD (sh /home/asd/device_info.sh)
Mar 25 18:02:01 -Latitude-3490 CRON[14811]: pam_unix(cron:session): session closed for user root
Mar 25 18:03:01 -Latitude-3490 CRON[14857]: pam_unix(cron:session): session opened for user root by (uid=0)
Mar 25 18:03:01 -Latitude-3490 CRON[14858]: (root) CMD (sh /home/asd/device_info.sh)
Mar 25 18:03:01 -Latitude-3490 CRON[14857]: pam_unix(cron:session): session closed for user root
Mar 25 18:04:01 -Latitude-3490 CRON[14866]: pam_unix(cron:session): session opened for user root by (uid=0)
Mar 25 18:04:01 -Latitude-3490 CRON[14867]: (root) CMD (sh /home/asd/device_info.sh)
Mar 25 18:05:01 -Latitude-3490 CRON[14879]: pam_unix(cron:session): session opened for user root by (uid=0)
Mar 25 18:05:01 -Latitude-3490 CRON[14880]: (root) CMD (sh /home/asd/device_info.sh)
答案 0 :(得分:0)
首先请参阅:https://unix.stackexchange.com/a/150556
这是针对您情况的快速问题。
一个移动设备的序列号:
#!/bin/bash
SERIAL="XX-XXXXXXXXXXXXXXXXXXXXXXXX"
TOKEN="XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
CHATID="XXXXXXXXX"
# stuff
MSG="*server hostname:*
$(uname -n)
*mobile device info:*
$(adb -s "$SERIAL" shell getprop ro.product.manufacturer)
$(adb -s "$SERIAL" shell getprop ro.product.model)
$(adb -s "$SERIAL" shell dumpsys battery | grep -Eo '(level|health).*' )"
curl -s https://api.telegram.org/bot"$TOKEN"/sendMessage \
-d "chat_id=$CHATID&text=$MSG&parse_mode=markdown" > /dev/null
# end stuff
对于devices.txt
文件中的空格分隔的序列,应添加
...
for SERIAL in $(cat devices.txt)
do
# stuff
...
...
# end stuff
done
将作业添加到crontab
* * * * * exec /root/get_device_info