mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-02-10 20:02:31 +00:00
Updated to .NET Core
130
Scheduling-exports-with-Cron.md
Normal file
130
Scheduling-exports-with-Cron.md
Normal file
@@ -0,0 +1,130 @@
|
||||
Make sure you already have **DiscordChatExporter.CLI** and **.NET Core** properly installed ([instructions here](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Linux-usage-instructions)).
|
||||
|
||||
You can use Cron on macOS, but [this method](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Scheduling-exports-on-macOS) is preferred.
|
||||
|
||||
#
|
||||
|
||||
**1.** Open Terminal and create a new text file with `nano /path/to/DiscordChatExporter/cron.sh`
|
||||
|
||||
**2.** Paste the following into the text file:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# Info: https://github.com/Tyrrrz/DiscordChatExporter/wiki
|
||||
|
||||
TOKEN=tokenhere
|
||||
TOKENTYPE=bot/user
|
||||
CHANNELID=channelhere
|
||||
DLLFOLDER=dceFOLDERpathhere
|
||||
FILENAME=filenamehere
|
||||
EXPORTDIRECTORY=dirhere
|
||||
EXPORTFORMAT=formathere
|
||||
# Available export formats: plaintext, htmldark, htmllight, json, csv
|
||||
# /\ CaSe-SeNsItIvE /\
|
||||
# You can edit the export command on line 40 if you'd like to include more options like date ranges and date format. You can't use partitioning (-p) with this script.
|
||||
|
||||
# This will verify if EXPORTFORMAT is valid and will set the final file extension according to it. If the format invalid, the script will display a message and exit.
|
||||
if [[ "$EXPORTFORMAT" == "plaintext" ]]; then
|
||||
FORMATEXT=.txt
|
||||
elif [[ "$EXPORTFORMAT" == "htmldark" ]] || [[ "$EXPORTFORMAT" == "htmllight" ]]; then
|
||||
FORMATEXT=.html
|
||||
elif [[ "$EXPORTFORMAT" == "json" ]]; then
|
||||
FORMATEXT=.json
|
||||
elif [[ "$EXPORTFORMAT" == "csv" ]]; then
|
||||
FORMATEXT=.csv
|
||||
else
|
||||
echo "$EXPORTFORMAT - Unknown export format"
|
||||
echo "Available export formats: plaintext, htmldark, htmllight, csv, json"
|
||||
echo "/\ CaSe-SeNsItIvE /\\"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# This will change the script's directory to DLLPATH, if unable to do so, the script will exit.
|
||||
cd $DLLFOLDER || exit 1
|
||||
|
||||
# This checks if you've typed "bot" on TOKENTYPE
|
||||
if [[ "$TOKENTYPE" == "bot" ]]; then
|
||||
ISBOTYES=-b
|
||||
fi
|
||||
|
||||
# This will export your chat
|
||||
dotnet DiscordChatExporter.Cli.dll export -t $TOKEN $ISBOTYES -c $CHANNELID -f $EXPORTFORMAT -o $FILENAME.tmp
|
||||
|
||||
# This sets the current time to a variable
|
||||
CURRENTTIME=$(date +"%Y-%m-%d-%H-%M-%S")
|
||||
|
||||
# This will move the .tmp file to the desired export location, if unable to do so, it will attempt to delete the .tmp file.
|
||||
if ! mv "$FILENAME.tmp" "${EXPORTDIRECTORY//\"}/$FILENAME-$CURRENTTIME$FORMATEXT" ; then
|
||||
echo "Unable to move $FILENAME.tmp to $EXPORTDIRECTORY/$FILENAME-$CURRENTTIME$FORMATEXT."
|
||||
echo "Cleaning up..."
|
||||
if ! rm -Rf "$FILENAME.tmp" ; then
|
||||
echo "Unable to remove $FILENAME.tmp."
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
```
|
||||
|
||||
**3.** Replace:
|
||||
|
||||
`tokenhere` with your [Token](https://github.com/Tyrrrz/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`
|
||||
|
||||
`channelhere` with a [Channel ID](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Obtaining-Token-and-Channel-IDs)
|
||||
|
||||
`dceFOLDERpathhere` with DCE's **directory path** (e.g. `/path/to/folder`, NOT `/path/to/folder/DiscordChatExporter.DLL`)
|
||||
|
||||
`filenamehere` with the exported channel's filename, without spaces
|
||||
|
||||
`dirhere` with the export directory (e.g. /home/user/Documents/Discord\ Exports)
|
||||
|
||||
`formathere` with one of the available export formats
|
||||
|
||||
**Remember to escape spaces** (add `\` before spaces) or to quote (") the paths (`"/home/user"`)!<br/><br/>
|
||||
|
||||
**4.** Make your script executable with `chmod +x /path/to/DiscordChatExporter/cron.sh`
|
||||
|
||||
**5.** Now let's edit the cron file. If you want to run the script with your user privileges, edit it by running `crontab -e`. If you want to run the script as root, edit it with `sudo crontab -e`.<br/>
|
||||
If it's your first time running this command, you might be asked to select a text editor.
|
||||
|
||||
**6.** Add the following to the end of the file `* * * * * /path/to/DiscordChatExporter/cron.sh >/tmp/discordchatexporter.log 2>/tmp/discordchatexportererror.log`<br/>
|
||||
Don't forget to replace the `/path/to/DiscordChatExporter/cron.sh`!
|
||||
> 💡 Tip: If you don't want logs to be created, replace both `/tmp/discordchatexporter.log` with `/dev/null`
|
||||
|
||||
Then replace the *s according to:
|
||||
|
||||

|
||||
|
||||
#
|
||||
|
||||
**Examples**
|
||||
|
||||
If you want to execute the script at minute 15 of every hour: `15 * * * *`
|
||||
|
||||
Every 30 minutes `*/30 * * * *`
|
||||
|
||||
Everyday at midnight `0 0 * * *`
|
||||
|
||||
Everyday at noon `0 12 * * *`
|
||||
|
||||
Everyday at 3, 4 and 6 PM `0 15,16,18 * * *`
|
||||
|
||||
Every Wednesday at 9 AM `0 9 * * 3`
|
||||
|
||||
Verify your cron time [here](https://crontab.guru).
|
||||
|
||||
#
|
||||
**Extra information**
|
||||
|
||||
The week starts on Sunday. 0 = SUN, 1 = MON...
|
||||
|
||||
Be aware that if you set the day to '31', the script will only run on months that have the 31th day.
|
||||
> 💡 Tip: [Learn more about running a cron job on the last day of the month here](https://stackoverflow.com/questions/6139189/cron-job-to-run-on-the-last-day-of-the-month) (EXPERT).
|
||||
|
||||
The default filename for the exported channel is `YYYY-MM-DD-hh-mm-ss-yourfilename`. You can change it if you'd like.
|
||||
|
||||
Don't forget to update your token in the script after regenerating it or resetting your password!
|
||||
|
||||
#
|
||||
Special thanks to [@RenanYudi](https://github.com/RenanYudi)
|
||||
@@ -1,115 +0,0 @@
|
||||
# » OUTDATED «
|
||||
# This guide will NOT work as of 2.16
|
||||
|
||||
Make sure you have DiscordChatExporter and Mono properly installed ([instructions here](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Linux-usage-instructions)).
|
||||
|
||||
You can use Cron on macOS, but [this method](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Scheduling-exports-on-macOS) is preferred.
|
||||
|
||||
#
|
||||
|
||||
**1.** Open Terminal, create a new script with `sudo nano /path/to/DiscordChatExporter/cron.sh`
|
||||
|
||||
**2.** Paste the following into the file:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# Info: https://github.com/Tyrrrz/DiscordChatExporter/wiki
|
||||
|
||||
TOKEN=<token>
|
||||
TOKENTYPE=<BOT/USER>
|
||||
CHANNEL=<channel>
|
||||
EXEPATH=<exe>
|
||||
FILENAME=<name>
|
||||
EXPORTDIRECTORY=<dir>
|
||||
EXPORTFORMAT=<format>
|
||||
# Available export formats: PlainText, HtmlDark, HtmlLight, Csv
|
||||
# /\ CaSe-SeNsItIvE /\
|
||||
|
||||
cd $EXEPATH || exit 1
|
||||
|
||||
if [[ "$TOKENTYPE" == "BOT" ]]; then
|
||||
ISBOTYES=-b
|
||||
fi
|
||||
|
||||
PATH=/Library/Frameworks/Mono.framework/Versions/Current/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
|
||||
|
||||
mono DiscordChatExporter.Cli.exe export -t $TOKEN $ISBOTYES -c $CHANNEL -f $EXPORTFORMAT -o $FILENAME.tmp
|
||||
CURRENTTIME=$(date +"%Y-%m-%d-%H-%M-%S")
|
||||
|
||||
if [[ "$EXPORTFORMAT" == "PlainText" ]]; then
|
||||
mv "$FILENAME.tmp" "${EXPORTDIRECTORY//\"}/$FILENAME-$CURRENTTIME.txt"
|
||||
|
||||
elif [[ "$EXPORTFORMAT" == "HtmlDark" ]] || [[ "$EXPORTFORMAT" == "HtmlLight" ]]; then
|
||||
mv "$FILENAME.tmp" "${EXPORTDIRECTORY//\"}/$FILENAME-$CURRENTTIME.html"
|
||||
|
||||
elif [[ "$EXPORTFORMAT" == "Csv" ]]; then
|
||||
mv "$FILENAME.tmp" "${EXPORTDIRECTORY//\"}/$FILENAME-$CURRENTTIME.csv"
|
||||
else
|
||||
echo "$EXPORTFORMAT - Unknown export format"
|
||||
echo "Available export formats: PlainText, HtmlDark, HtmlLight, Csv"
|
||||
echo "/\ CaSe-SeNsItIvE /\\"
|
||||
if ! rm -Rf "$FILENAME.tmp" ;then
|
||||
echo "Unable to delete $PWD/$FILENAME.tmp"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
```
|
||||
|
||||
**3.** Replace:
|
||||
|
||||
`<token>` with your [Token](https://github.com/Tyrrrz/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/Tyrrrz/DiscordChatExporter/wiki/Obtaining-Token-and-Channel-IDs)
|
||||
|
||||
`<exe>` with the .exe **directory's path** (e.g. /home/user/DiscordChatExporter)
|
||||
|
||||
`<name>` with a filename without spaces
|
||||
|
||||
`<dir>` with the export directory (e.g. /home/user/Documents/Discord\ Exports)
|
||||
|
||||
`<format>` with one of the available export formats
|
||||
|
||||
**Remember to escape spaces** (add `\` before spaces)!<br/><br/>
|
||||
|
||||
**4.** Give the 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/discordchatexporter.log 2>/tmp/discordchatexportererror.log` to the end of the file
|
||||
|
||||
Replace the *s according to:
|
||||
|
||||

|
||||
|
||||
#
|
||||
**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 `/var/spool/cron/crontabs` on Linux, and at `/usr/lib/cron/tabs` on macOS, 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).
|
||||
|
||||
#
|
||||
Special thanks to [@RenanYudi](https://github.com/RenanYudi)
|
||||
Reference in New Issue
Block a user