In this guide we’ll be going over on how to get discord notifications when rclone have completed it’s daily upload.
Here’s an example of want it would look like
Discord setting
I like to keep my rclone stuff private form other users so I’ve created a dedicated channel for rclone notifications.
In order to get started you need to create discord webhook:
https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
Follow these simple steps and save the webhook link. We’ll be using it later on.
RClone Move Script
You most like already have a rclone move script up and running. Some with default QuickBox Pro settings others with modifications.
This guide will be providing a new move script. Feel free to modify the rclone move flags as you like. For beginners I suggest you leave it default.
SSH into your server and elevate session sudo su -
and navigation into your rclone folder cd /home/USERNAME/rclone
Next we will grab the script and assign permissions to it. Run line by line
wget https://lab.quickbox.io/QuickBox/Pro/-/raw/master/bin/rclonediscord.sh chown -cR 1000:1000 rclonediscord.sh chmod +x rclonediscord.sh
Fancy a preview of the script?
#!/bin/bash # # rclone upload script with optional Discord notification upon move completion (if something is moved) # Credit to @XantherBanter - Github # # ----------------------------------------------------------------------------- SOURCE_DIR="/home/USERNAME/rclone/cache/" DESTINATION_DIR="gdrive:Media" DISCORD_WEBHOOK_URL="InsertDiscordWebhookURLHere" DISCORD_ICON_OVERRIDE="https://i.imgur.com/MZYwA1I.png" DISCORD_NAME_OVERRIDE="RCLONE" LOCK_FILE="/home/USERNAME/rclone/rclone-upload.lock" LOG_FILE="/home/USERNAME/rclone/rclone-upload.log" # DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING # ----------------------------------------------------------------------------- trap 'rm -f $LOCK_FILE; exit 0' SIGINT SIGTERM if [ -e "$LOCK_FILE" ]; then echo "$0 is already running." exit else touch "$LOCK_FILE" rclone_move() { rclone_command=$( /usr/bin/rclone move -P \ --config="$HOME"/.config/rclone/rclone.conf \ --use-mmap \ --drive-chunk-size 64M \ --bwlimit 8M \ --delete-empty-src-dirs \ --user-agent user \ --fast-list \ --log-file="$LOG_FILE" \ --stats=9999m \ --drive-stop-on-upload-limit \ "$SOURCE_DIR" "$DESTINATION_DIR" 2>&1 ) # "--stats=9999m" mitigates early stats output # "2>&1" ensures error output when running via command line echo "$rclone_command" } rclone_move if [ "$DISCORD_WEBHOOK_URL" != "" ]; then rclone_sani_command="$(echo $rclone_command | sed 's/\x1b\[[0-9;]*[a-zA-Z]//g')" # Remove all escape sequences # Notifications assume following rclone ouput: # Transferred: 0 / 0 Bytes, -, 0 Bytes/s, ETA - Errors: 0 Checks: 0 / 0, - Transferred: 0 / 0, - Elapsed time: 0.0s transferred_amount=${rclone_sani_command#*Transferred: } transferred_amount=${transferred_amount%% /*} send_notification() { output_transferred_main=${rclone_sani_command#*Transferred: } output_transferred_main=${output_transferred_main% Errors*} output_errors=${rclone_sani_command#*Errors: } output_errors=${output_errors% Checks*} output_checks=${rclone_sani_command#*Checks: } output_checks=${output_checks% Transferred*} output_transferred=${rclone_sani_command##*Transferred: } output_transferred=${output_transferred% Elapsed*} output_elapsed=${rclone_sani_command##*Elapsed time: } notification_data='{ "username": "'"$DISCORD_NAME_OVERRIDE"'", "avatar_url": "'"$DISCORD_ICON_OVERRIDE"'", "content": null, "embeds": [ { "title": "Rclone Upload Task: Success!", "color": 4094126, "fields": [ { "name": "Transferred", "value": "'"$output_transferred_main"'" }, { "name": "Errors", "value": "'"$output_errors"'" }, { "name": "Checks", "value": "'"$output_checks"'" }, { "name": "Transferred", "value": "'"$output_transferred"'" }, { "name": "Elapsed time", "value": "'"$output_elapsed"'" } ], "thumbnail": { "url": null } } ] }' /usr/bin/curl -H "Content-Type: application/json" -d "$notification_data" $DISCORD_WEBHOOK_URL } if [ "$transferred_amount" != "0" ]; then send_notification fi fi rm -f "$LOCK_FILE" trap - SIGINT SIGTERM exit fi
Next we will need to edit the rclonediscord.sh
script and insert the newly created discord webhook.
Run:
nano rclonediscord.sh
Edit the highlighted lines.
Replace USERNAME with your username
Insert your discord URL.
SOURCE_DIR="/home/USERNAME/rclone/cache/" DESTINATION_DIR="gdrive:Media" DISCORD_WEBHOOK_URL="InsertDiscordWebhookURLHere" DISCORD_ICON_OVERRIDE="https://i.imgur.com/MZYwA1I.png" DISCORD_NAME_OVERRIDE="RCLONE" LOCK_FILE="/home/USERNAME/rclone/rclone-upload.lock" LOG_FILE="/home/USERNAME/rclone/rclone-upload.log"
QuickBox Pro rclone encrypted users; you will also need to edit line #2. Replace gdrive:Media
with crypt:
Enabling the script
Since QuickBox rclone is already installed and running, we will need to stop the current move job and enable the discord notification script.
Edit the cron job and comment out the move.sh
script and add a new line for rclonediscord.sh
by running crontab -e
Example crontab
#0 3 12 * * /home/USERNAME/rclone/move.sh 0 3 12 * * /home/USERNAME/rclone/rclonediscord.sh
Note: your crontab list will most like have more entries
Final notes
Rclone Dashboard functionality is still bound to the original install. Meaning hitting the upload or log buttons will run and read the original move.sh
script. The only change we’ve made to the initial install is that we’ve stopped the daily default upload script and replaced it with the new rclone discord notification script.
A new upload log file will also be generated called rclone-upload.log
As this is a userscript QuickBox Pro staff cannot support any issue you may experience. But we will of course do our best to support you.
Enjoy! 🙂