다운로드 완료 알림 및 다운로드목록 자동 삭제
다운로드가 완료되면 텔레그램봇으로 다운로드 완료 여부를 안내하고. Transmision에서 다운로드 완료 항목에 대한
리스트를 자동삭제하는 스크립입니다.
"tr.sh"라는 파일명으로 아래 스크립트를 작성 합니다.
텔레그램봇에 대한 부분은 설명을 생략하며 구글을 검색하시면 많은 정보들이 있습니다.
1. 도커 콘솔에 접속 합니다.
2. "/config"로 이동해 "tr.sh"라는 파일을 생성합니다.
cd config
touch tr.sh
3. nano를 이용해 "tr.sh" 내용을 작성합니다.
nano tr.sh
입력해야할 내용은 아래와 같습니다. 내역 작성 후 ctrl + x 로 빠져나가고 엔터를 쳐줍니다.
#!/bin/sh
# telegram bot
SERVER="9091"
TOKEN='텔레그램_TOKEN'
CHAT_ID="텔레그램챗_ID"
URL='https://api.telegram.org/bot'$TOKEN
MSG_URL=$URL'/sendMessage?chat_id='
sleep 1s
# torrent remove
TORRENTLIST=`transmission-remote $SERVER --list | sed -e '1d;$d;s/^ *//' | cut -s -d " " -f 1`
for TORRENTID in $TORRENTLIST
do
FILENAME=`/usr/bin/transmission-remote $SERVER --torrent $TORRENTID --info | grep Name | cut -c 9-60`
DL_COMPLETED=`transmission-remote $SERVER --torrent $TORRENTID --info | grep "Percent Done: 100%"`
STATE_STOPPED=`transmission-remote $SERVER --torrent $TORRENTID --info | grep "State: Seeding\|Stopped\|Finished\|Idle"`
if [ "$DL_COMPLETED" ] && [ "$STATE_STOPPED" ]; then
transmission-remote $SERVER --torrent $TORRENTID --remove
# telegram message send
/usr/bin/curl --data-urlencode "text=Download Complete : $FILENAME" "$MSG_URL"$CHAT_ID"&"
fi
done
Log를 남기고 싶으면 아래 문장을 끝부분에 추가해 주시면 됩니다.
LOG_FILE=/config/tr.log
transmission-remote $SERVER --list >>$LOG_FILE
4. 도커에서 "tr.sh"를 실행할 수 있는 권한을 부여해 줍니다.
chmod +x tr.sh
5. 도커 콘솔을 빠져나갔니다.
6. 작성한 "tr.sh"를 Transmission에 등록이 필요 합니다. Transmission GUI 페이지로 접속 후 "Settings"로 이동합니다.
"Torrets" 탭을 보면 "Run script when complete"라는 항목이 있고, 이 옵션을 활성화 합니다.
활성화 후 작성된 "/config/tr.sh"를 등록해 주시고, 도커를 재시작 합니다.
또는 "settings.json"에 아래 내용출 추가하여 "tr.sh" 파일을 적용 시켜 줄수도 있습니다.
"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/config/tr.sh",
JSON을 수정할 때 아래도 같이 해주시며 좋습니다.
"ratio-limit": 0,
"ratio-limit-enabled": true,
"blocklist-enabled": true,
"blocklist-url": "http://list.iblocklist.com/?list=bt_level1&fileformat=p2p&archiveformat=gz",