Skip to content

Instantly share code, notes, and snippets.

@Isengo1989
Last active April 12, 2024 06:53
Show Gist options
  • Save Isengo1989/b04bfe814f7bd3d56d92ceaa113bc44f to your computer and use it in GitHub Desktop.
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
#!/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