Как разрешить нескольким пользователям доступ к одному и тому же crontab в Debian Linux v8.4?

1077
Michael

Я пытаюсь создать crontab для группы пользователей, давайте назовем группу «testGroup». Есть 3 пользователя, и я хочу дать всем им доступ к одному и тому же crontab. Я провел небольшое исследование и попытался добавить каждого отдельного пользователя в группу crontab в файле / etc / group. Однако это не сработало, поскольку для каждого пользователя есть еще 3 отдельных crontab. Это можно исправить? Если так, то как бы я поступил так?

Спасибо

1

1 ответ на вопрос

1
kostix

Background

No, cron does not work the way you assume it does.

The cron daemon reads its crontabs from two places:

  • System-wide /etc/crontab;
  • Per-user crontabs.

There's no concept of per-group-of-users crontabs.

Solution

Debian has customized cron which allows to do what you need relatively easily. To cite the cron(8) manual page:

Additionally, in Debian, cron reads the files in the /etc/cron.d directory. cron treats the files in /etc/cron.d as in the same way as the /etc/crontab file (they follow the special format of that file, i.e. they include the user field). However, they are independent of /etc/crontab: they do not, for example, inherit environment variable settings from it. This change is specific to Debian see the note under DEBIAN SPECIFIC below.

Hence I would do the following:

  1. Create a dedicated group for your group of users. Let's assume it's "mycrontab".

  2. Add your three users into that group.

  3. Create a file under /etc/cron.d and make it be owned by root:mycrontab and has permission bits set to 0660 or rw-rw-r--, that is, read/write access to the user root and group mycrontab and read access to everyone else.

  4. Teach your users about where to locate this file and the rules about its format (those could be placed in the file in the form of comments).

Note that you might need to figure out how to handle sending mails to all your users. I'd check if it's OK to set the MAILTO environment variable obeyed by cron to a comma-separated list of e-mail addresses first (like joe@domain.lan,jane@domain.lan,jill@domain.lan) or, failing that, you'd probably need to set up a mail alias either in your local MTA or the MTA receiving mails generated by cron on your system, and use the value of this alias for the MAILTO variable.

All in all, please give the cron(8) and crontab(5) manual pages at least a cursory glance.

…and please remove your users from the crontab group!

Похожие вопросы