Last active
April 12, 2024 06:53
-
-
Save Isengo1989/b04bfe814f7bd3d56d92ceaa113bc44f to your computer and use it in GitHub Desktop.
Small script to save EOD (end of day) / work log messages and output them when needed. Can also be used to publish via Slack webhook
This file contains hidden or 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
#!/bin/bash | |
# Use a variable for the text file name | |
textFileName="/home/YOUR_USER/eod.txt" | |
# Config variable for time logging (adds datetime infront of each entry) | |
timeLogged=false | |
# Slack webhook URL (only used on publish) | |
slackWebhook="https://hooks.slack.com/services/XXXXXXXXXXXXXXXX/XXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXXX" | |
# Name | |
userName="Micha" | |
# Disallow a third parameter | |
if [ $# -gt 2 ]; then | |
echo "Only two parameters are allowed. The second parameter should be in quotes." | |
exit 1 | |
fi | |
# Check the first input option | |
case $1 in | |
log) | |
# Save the second input in a file | |
if $timeLogged; then | |
echo "$(date) - $2" >> $textFileName | |
else | |
echo "- $2" >> $textFileName | |
fi | |
;; | |
output) | |
# Output the content of the file | |
echo "EOD" | |
cat $textFileName | |
;; | |
clear) | |
# Empty the file | |
> $textFileName | |
;; | |
publish) | |
# Send the output of the file to Slack via webhook | |
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"*EOD - $userName* \n $(cat $textFileName)\"}" $slackWebhook | |
;; | |
*) | |
echo "Invalid option. Please use log, output, or clear." | |
exit 1 | |
;; | |
esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment