-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogpost
More file actions
37 lines (32 loc) · 1.18 KB
/
logpost
File metadata and controls
37 lines (32 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
APIURL="https://api.mclo.gs/1/log"
DCWebhook="https://discord.com/api/webhooks/CHANGEME"
if [ -z "$1" ]; then
echo "Usage: $0 <server>"
exit 1
fi
backupDir="/home/game/backups/logs/$1"
crashReportsDir="/home/game/$1/crash-reports"
# loop files in $crashReportsDir
for file in $crashReportsDir/*; do
if [ -f "$file" ]; then
echo "Found crash log: $file"
# post log
content=$(cat $file | sed 's/"//g')
response=$(curl -X POST -d "content=$content" -H "Content-Type: application/x-www-form-urlencoded" $APIURL)
# Response is in json format.
success=$(echo "$response" | jq -r '.success')
url=$(echo "$response" | jq -r '.url')
raw=$(echo "$response" | jq -r '.raw')
if [ "$success" = "true" ]; then
# Send discord webhook
curl -X POST -d "content=Crash Log for $1: $url" -H "Content-Type: application/x-www-form-urlencoded" $DCWebhook
# Make sure the backup directory exists
mkdir -p "$backupDir/crash"
# move sent file to archive
mv "$file" "$backupDir/crash/$(basename $file)"
else
echo "Failure!"
fi
fi
done