Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env -S bash
- TOKEN=""
- CHAT_ID=""
- declare -A PIDS
- function notify() {
- local URL="$1"
- local PID="$2"
- local MESSAGE="$3"
- wget -qO->>/dev/null -U "GayRobot (like TelegramBot)" \
- --post-data "chat_id=${CHAT_ID}&text=<b><a href=\"${URL}\">${PID}</a> ${MESSAGE}</b>&parse_mode=HTML&disable_web_page_preview=True" \
- "https://api.telegram.org/bot${TOKEN}/sendMessage"
- }
- function check() {
- local PID=$1
- [[ -d "/proc/${PID}" ]] && return 0 || return 1
- }
- function download() {
- local URL="$1"
- local NAME="$2"
- PIDS["$URL"]+=$(wget --no-check-certificate -U "Mozilla/5.0" -qO "$NAME" -bc "$URL" | grep -Ewo "[0-9]+")
- }
- function main() {
- while IFS=' ' read -r link name; do download "$link" "$name"; done < links.txt # format: https://example.com/deb.iso deb.iso
- while [[ "${#PIDS[@]}" != 0 ]]; do
- for k in "${!PIDS[@]}"; do
- if [[ $(check ${PIDS["$k"]}; echo $?) != 0 ]]; then
- notify "$k" "${PIDS["$k"]}" "download is complete."
- unset "PIDS["$k"]"
- sleep 3s
- fi
- done
- sleep 60s
- done
- exit 0
- }
- main & disown
- echo "main PID: $!"
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement