Created Scheduling exports with Mono & Crontab (markdown)

Alexey Golub
2018-09-12 21:50:07 +03:00
parent 8dc5ace097
commit a35aee7856

@@ -0,0 +1,99 @@
**This guide is for macOS and Linux.**
#
Make sure you already have DiscordChatExporter and Mono properly installed ([instructions here](https://github.com/RenanYudi/DiscordChatExporter/wiki/Linux-usage-instructions)):
**1.** Open Terminal, create a new script with `sudo nano /path/to/DiscordChatExporter/cron.sh`
**2.** Paste the following into the file:
```
#!/bin/bash
# Info: https://github.com/Tyrrrz/DiscordChatExporter
TOKEN=<token>
TOKENTYPE=<BOT/USER>
CHANNEL=<channel>
EXEPATH=<exe>
FILENAME=<name>
EXPORTDIRECTORY=<dir>
EXPORTFORMAT=<format>
# Available export formats: PlainText, HtmlDark, HtmlLight, Csv
cd $EXEPATH || exit
if [[ "$TOKENTYPE" == "BOT" ]]; then
ISBOTYES=-b
fi
PATH=/Library/Frameworks/Mono.framework/Versions/Current/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
CURRENTTIME=`date +"%Y-%m-%d-%H-%M-%S"`
mono DiscordChatExporter.Cli.exe -t $TOKEN $ISBOTYES -c $CHANNEL -f $EXPORTFORMAT -o exporttmp
if [[ "$EXPORTFORMAT" == "PlainText" ]]; then
mv "exporttmp" $EXPORTDIRECTORY/$FILENAME-$CURRENTTIME.txt
elif [[ "$EXPORTFORMAT" == "Html"* ]]; then
mv "exporttmp" $EXPORTDIRECTORY/$FILENAME-$CURRENTTIME.html
elif [[ "$EXPORTFORMAT" == "Csv" ]]; then
mv "exporttmp" $EXPORTDIRECTORY/$FILENAME-$CURRENTTIME.csv
else
exit
fi
exit
```
**3.** Replace:
`<token>` with your [Token](https://github.com/RenanYudi/DiscordChatExporter/wiki/Obtaining-Token-and-Channel-IDs)
`<BOT/USER>` If the Token is from a bot replace it with `BOT`, if it's from a user, `USER`.
`<channel>` with a [Channel ID](https://github.com/RenanYudi/DiscordChatExporter/wiki/Obtaining-Token-and-Channel-IDs)
`<exe>` with the .exe path (e.g. /home/user/DiscordChatExporter.Cli.exe)
`<name>` with a filename without spaces
`<dir>` with the export directory without quotes (e.g. /home/user/Documents/CronExport)
`<format>` with one of the available export formats.
**4.** Give the shell script permissions with `sudo chmod 755 /path/to/DiscordChatExporter/cron.sh`
**5.** Add a new job to crontab using `sudo crontab e`
**6.** Add `* * * * * /path/to/DiscordChatExporter/cron.sh >/tmp/discordexporter.log 2>/tmp/discordexportererror.log` to the end of the file.
Replace the *s according to:
![](https://i.imgur.com/gEWvOhS.png)
#
**Extra Info.**
Week starts on Sunday. 0 = SUN, 1 = MON...
Filename date format is YYYY-MM-DD-hh-mm-ss.
The cron file is located at `/usr/lib/cron/tabs` on macOS, and at `/var/spool/cron/crontabs` on Linux, but should always be edited with `crontab -e`.
#
**Examples**
If you want to execute the script at minute 15 of every hour: `15 * * * *`
Every 5 minutes `*/5 * * * *`
Everyday at midnight `0 0 * * *`
Everyday at noon `0 12 * * *`
Everyday at 3, 4, 6 PM `0 15,16,18 * * *`
Every Wednesday at 9 AM `0 9 * * 3`
Verify your cron time [here](https://crontab.guru).
#
Credits to [@RenanYudi](https://github.com/RenanYudi)