- Create a dedicated discord server, create a webhook to the server and copy the webhook link.
- Replace in discord_notifier.py with copied webhook link and save the file to a location.
- Copy the location and replace ~/.custom-commands/lib/Notifire with your location in the .bashrc file in this gist.
- Now copy paste the modified .bashrc content in this gist to your terminal startup script.
- Run any command followed by notifier and get notification on discord. (for ex:
notifire sleep 2
) - Video guide here
Last active
February 8, 2021 07:31
-
-
Save sayan1999/b9d976a71d4aa0d3578fe9fa8a9dabff to your computer and use it in GitHub Desktop.
Linux Command Completion Status Notifier on Discord Channel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# put the snippet in your .bashrc or .zshrc (or the shell you prefer to use) | |
# and call it like ```notifire <command>``` | |
# ```notifire sleep 5``` | |
notifire() | |
{ | |
"$@" | |
ret=$? | |
if [[ $ret -eq 0 ]] | |
then | |
# "~/.custom-commands/lib/Notifire" is the path where I kept the webhook python script | |
python3 ~/.custom-commands/lib/Notifire/discord_notifier.py $(uname) $(hostname) Successfully ran $@ | |
else | |
python3 ~/.custom-commands/lib/Notifire/discord_notifier.py $(uname) $(hostname) Failed $@ | |
fi | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is the python script to notify via discord channel | |
import requests, sys | |
url = "<discord webhook url here>" | |
data = { | |
} | |
data["embeds"] = [ | |
{ | |
"description" : f"{' '.join(sys.argv[1:])}", | |
"title" : f"Notification from {' '.join(sys.argv[1:3])}" | |
} | |
] | |
result = requests.post(url, json = data) | |
try: | |
result.raise_for_status() | |
except requests.exceptions.HTTPError as err: | |
print('NotiFire Err', err) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment