Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macos] Crontab fix quick guide #122

Closed
fulcus opened this issue Oct 31, 2021 · 9 comments
Closed

[macos] Crontab fix quick guide #122

fulcus opened this issue Oct 31, 2021 · 9 comments
Labels
bug Something isn't working

Comments

@fulcus
Copy link

fulcus commented Oct 31, 2021

Since I spent some time dealing with crontab on macos I'll quickly describe here how to set it up correctly as it could be helpful for others.

Do as reported in the guide, but make sure to use the absolute path of moodle-dl:

  1. crontab -e
  2. Add */15 * * * * cd "/absolute/path/to/moodle/folder" && /Users/your_user/Library/Python/3.8/bin/moodle-dl
  3. Save and you're done!'

To get your actual moodle-dl location run which moodle-dl.

Now give cron permission to execute commands as shown here.
Finally if you want to remove those annoying mail messages in the terminal follow this guide.

@fulcus fulcus added the bug Something isn't working label Oct 31, 2021
@fulcus fulcus changed the title Crontab fix on macos quick guide [macos] Crontab fix quick guide Oct 31, 2021
@C0D3D3V
Copy link
Owner

C0D3D3V commented Oct 31, 2021

Thanks a lot I think it's cool that you also care about the Mac support :) I can only test now and then, for Windows, in a VM, but nothing more.

If you are interested you can also change the wiki entry directly. I think it's best to link to the wiki at the end of the --init execution, there we can explain more than in the terminal output.

@C0D3D3V
Copy link
Owner

C0D3D3V commented Nov 14, 2021

I have changed the description, would be great if you could test this before the release :)

@fulcus
Copy link
Author

fulcus commented Nov 15, 2021

If by test you mean repeat the procedure I described, I have just tried it again and it works as expected. Only addition I would make is to run which moodle-dl and put it in place of /Users/your_user/Library/Python/3.8/bin/moodle-dl as it might change depending on your python installation.

Also article 2 can be reassumed in: just add 2>&1 at the end of the crontab as in:

*/15 * * * * cd "/absolute/path/to/moodle/folder" && /Users/your_user/Library/Python/3.8/bin/moodle-dl > /dev/null

@C0D3D3V
Copy link
Owner

C0D3D3V commented Nov 15, 2021

Actually I meant if you could download the master branch and check if on macOS at the end of the execution of moodle-dl --init now in the cronjob proposal the absolute path to moodle-dl is displayed.

I have just added the suggestion with 2>&1.

@fulcus
Copy link
Author

fulcus commented Nov 16, 2021

If by test you mean repeat the procedure I described, I have just tried it again and it works as expected. Only addition I would make is to run which moodle-dl and put it in place of /Users/your_user/Library/Python/3.8/bin/moodle-dl as it might change depending on your python installation.

Also article 2 can be reassumed in: just add 2>&1 at the end of the crontab as in:

*/15 * * * * cd "/absolute/path/to/moodle/folder" && /Users/your_user/Library/Python/3.8/bin/moodle-dl > /dev/null

Updated 2>&1 to > /dev/null

I will test master in the following days

@C0D3D3V
Copy link
Owner

C0D3D3V commented Nov 18, 2021

@C0D3D3V C0D3D3V closed this as completed Nov 19, 2021
@C0D3D3V
Copy link
Owner

C0D3D3V commented Nov 19, 2021

It is now released, you can test it in the new version :)

@fulcus
Copy link
Author

fulcus commented Nov 20, 2021

Tested on new version, this is my output (correct)

  To set a cron-job for this program on your Unix-System:
    1. `crontab -e`
    2. Add `*/15 * * * * cd "/Users/fulco/Desktop/test" && "/Users/fulco/Library/Python/3.8/bin/moodle-dl" >/dev/null 2>&1`
    3. Save and you're done!
For more ways to run `moodle-dl` periodically, take a look at the wiki (https://github.com/C0D3D3V/Moodle-Downloader-2/wiki/Start-Moodle-dl-periodically-or-via-Telegram)

Running it with the cronjob displayed upon configuration (only changed 15 to 1):

*/1 * * * * cd "/Users/fulco/Desktop/test" && "/Users/fulco/Library/Python/3.8/bin/moodle-dl" >/dev/null 2>&1`

The log is weird but moodle-dl works as expected.

2021-11-20 14:43:01  INFO  {main}  --- moodle-dl started ---------------------
2021-11-20 14:43:01  ERROR  {main}  Traceback (most recent call last):
  File "/Users/fulco/Library/Python/3.8/lib/python/site-packages/moodle_dl/main.py", line 260, in run_main
    process_lock.lock(storage_path)
  File "/Users/fulco/Library/Python/3.8/lib/python/site-packages/moodle_dl/utils/process_lock.py", line 21, in lock
    raise LockError('A downloader is already running. Delete {} if you think this is wrong.'.format(str(path)))
moodle_dl.utils.process_lock.LockError: A downloader is already running. Delete running.lock if you think this is wrong.

However I still receive cron mail as follows:

Subject: Cron <fulco@Francescos-Air> cd "/Users/fulco/Desktop/test" && "/Users/fulco/Library/Python/3.8/bin/moodle-dl" >/dev/null 2>&1`
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=fulco>
X-Cron-Env: <USER=fulco>
Date: Sat, 20 Nov 2021 14:50:00 +0100 (CET)

I think that this is due to >/dev/null 2>&1, whereas I only mean that I use > /dev/null and not 2>&1 anymore.

In conclusion my only working crontab is:

*/30 * * * * cd "/Users/fulco/desktop/poli" && /Users/fulco/Library/Python/3.8/bin/moodle-dl > /dev/null

I suggest to correct with this format.

@C0D3D3V
Copy link
Owner

C0D3D3V commented Nov 20, 2021

Moodle-dl does not print anything in std-err, so 2>&1 really does nothing.

The only difference is that when an error occurs, moodl-dl exits with 1 instead of 0 and thus causes cron to send out a mail. Like in your test, there was already another moodl-dl running, so the instance failed and made cron send a mail.

as your linked guide recommends, the best would be to simply write MAILTO="" in the first line so that no mail is sent at all. Or you can add || true to the end of the command, so that always 0 and not 1 is returned and cron never sends a mail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants