Skip to content

Instantly share code, notes, and snippets.

@stigfromsouth
Forked from thomasdarimont/logit.sh
Created July 7, 2022 07:24
Show Gist options
  • Save stigfromsouth/bb79bb5244171f93cc2f50d4edf16608 to your computer and use it in GitHub Desktop.
Save stigfromsouth/bb79bb5244171f93cc2f50d4edf16608 to your computer and use it in GitHub Desktop.
Simple bash script to demo logging to graylog via Gelf / UDP with netcat
#!/usr/bin/env bash
script_execution_id=$(uuidgen)
log_gelf(){
msg=$1
nc -w 1 -u logserver.tdlabs.local 12205 <<EOF
{
"version":"1.1"
, "host":"$(hostname)"
, "short_message":"$msg"
, "full_message":"$msg"
, "level":1
, "_script_execution_id":"$script_execution_id"
}\0
EOF
}
log_gelf "Hello from $0"
echo Do something...
log_gelf "Begin work..."
sleep 1
log_gelf "Step 1 ..."
echo ...
sleep 2
log_gelf "Step 2 ..."
sleep 2
echo ...
log_gelf "Work finished!"
echo work done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment