diff --git a/Scheduling-exports-with-Mono-&-Crontab.md b/Scheduling-exports-with-Mono-&-Crontab.md new file mode 100644 index 0000000..dae5a70 --- /dev/null +++ b/Scheduling-exports-with-Mono-&-Crontab.md @@ -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= +TOKENTYPE= +CHANNEL= +EXEPATH= +FILENAME= +EXPORTDIRECTORY= +EXPORTFORMAT= +# 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: + + `` with your [Token](https://github.com/RenanYudi/DiscordChatExporter/wiki/Obtaining-Token-and-Channel-IDs) + + `` If the Token is from a bot replace it with `BOT`, if it's from a user, `USER`. + + `` with a [Channel ID](https://github.com/RenanYudi/DiscordChatExporter/wiki/Obtaining-Token-and-Channel-IDs) + + `` with the .exe path (e.g. /home/user/DiscordChatExporter.Cli.exe) + + `` with a filename without spaces + + `` with the export directory without quotes (e.g. /home/user/Documents/CronExport) + + `` 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) \ No newline at end of file