Why does cron require MTA for logging?
Why does cron require MTA for logging? Is there any particular advantage to this? Why can't it create a log file like most other utilities?
networking cron logs email
add a comment |
Why does cron require MTA for logging? Is there any particular advantage to this? Why can't it create a log file like most other utilities?
networking cron logs email
add a comment |
Why does cron require MTA for logging? Is there any particular advantage to this? Why can't it create a log file like most other utilities?
networking cron logs email
Why does cron require MTA for logging? Is there any particular advantage to this? Why can't it create a log file like most other utilities?
networking cron logs email
networking cron logs email
edited 7 hours ago
Glorfindel
2891410
2891410
asked 15 hours ago
NikhilNikhil
352113
352113
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Consider that the traditional "standard" way of logging data is syslog, where the metadata included in the messages are the "facility code" and the priority level. The facility code can be used to separate log streams from different services so that they can be split into different log files, etc. (even though the facility codes are somewhat limited in that they have fixed traditional meanings.)
What syslog doesn't have, is a way to separate messages for or from different users, and that's something that cron
needs on a traditional multi-user system. It's no use collecting the messages from all users' cron jobs to a common log file where only the system administrator can see them. On the other hand, email naturally provides for sending messages to different users, so it's a logical choice here. The alternative would be for cron to do the work manually, and to create logfiles to each users' home directory, but a traditional multi-user Unix system would be assumed to have a working MTA, so implementing it in cron would have been mostly a futile exercise.
On modern systems, there might be alternative choices, of course.
add a comment |
I assume that by "logging" you mean storing the actual output of jobs. The running of jobs is already logged in the cron log in /var/cron/log
(the path may differ between systems). There is no MTA required for this log.
A cron job is run as the user whose crontab the job is part of.
In the general case, there is no guarantee that this user is able to create files on the system (a user may not be an interactive user), especially not under the /var
hierarchy where logs are usually created. The safest way to notify the user of errors and other output from a job is therefore to collect these and send them by email to the user. This would also allow the user to set up email redirection for the account to be able to see e.g. errors in their preferred location.
If the user wants to save the output of a job to file, they may do so with a simple redirection in the crontab:
0 */2 * * * "$HOME/scripts/myscript" >"$HOME/logs/myscript.log" 2>&1
This would run "$HOME/scripts/myscript"
every second hour, on the hour, and would save all output to "$HOME/logs/myscript.log"
. No emails would be created by running this job as all output is redirected. Without the 2>&1
, error messages would still be sent by email.
This allows the user to choose where the output goes.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505453%2fwhy-does-cron-require-mta-for-logging%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Consider that the traditional "standard" way of logging data is syslog, where the metadata included in the messages are the "facility code" and the priority level. The facility code can be used to separate log streams from different services so that they can be split into different log files, etc. (even though the facility codes are somewhat limited in that they have fixed traditional meanings.)
What syslog doesn't have, is a way to separate messages for or from different users, and that's something that cron
needs on a traditional multi-user system. It's no use collecting the messages from all users' cron jobs to a common log file where only the system administrator can see them. On the other hand, email naturally provides for sending messages to different users, so it's a logical choice here. The alternative would be for cron to do the work manually, and to create logfiles to each users' home directory, but a traditional multi-user Unix system would be assumed to have a working MTA, so implementing it in cron would have been mostly a futile exercise.
On modern systems, there might be alternative choices, of course.
add a comment |
Consider that the traditional "standard" way of logging data is syslog, where the metadata included in the messages are the "facility code" and the priority level. The facility code can be used to separate log streams from different services so that they can be split into different log files, etc. (even though the facility codes are somewhat limited in that they have fixed traditional meanings.)
What syslog doesn't have, is a way to separate messages for or from different users, and that's something that cron
needs on a traditional multi-user system. It's no use collecting the messages from all users' cron jobs to a common log file where only the system administrator can see them. On the other hand, email naturally provides for sending messages to different users, so it's a logical choice here. The alternative would be for cron to do the work manually, and to create logfiles to each users' home directory, but a traditional multi-user Unix system would be assumed to have a working MTA, so implementing it in cron would have been mostly a futile exercise.
On modern systems, there might be alternative choices, of course.
add a comment |
Consider that the traditional "standard" way of logging data is syslog, where the metadata included in the messages are the "facility code" and the priority level. The facility code can be used to separate log streams from different services so that they can be split into different log files, etc. (even though the facility codes are somewhat limited in that they have fixed traditional meanings.)
What syslog doesn't have, is a way to separate messages for or from different users, and that's something that cron
needs on a traditional multi-user system. It's no use collecting the messages from all users' cron jobs to a common log file where only the system administrator can see them. On the other hand, email naturally provides for sending messages to different users, so it's a logical choice here. The alternative would be for cron to do the work manually, and to create logfiles to each users' home directory, but a traditional multi-user Unix system would be assumed to have a working MTA, so implementing it in cron would have been mostly a futile exercise.
On modern systems, there might be alternative choices, of course.
Consider that the traditional "standard" way of logging data is syslog, where the metadata included in the messages are the "facility code" and the priority level. The facility code can be used to separate log streams from different services so that they can be split into different log files, etc. (even though the facility codes are somewhat limited in that they have fixed traditional meanings.)
What syslog doesn't have, is a way to separate messages for or from different users, and that's something that cron
needs on a traditional multi-user system. It's no use collecting the messages from all users' cron jobs to a common log file where only the system administrator can see them. On the other hand, email naturally provides for sending messages to different users, so it's a logical choice here. The alternative would be for cron to do the work manually, and to create logfiles to each users' home directory, but a traditional multi-user Unix system would be assumed to have a working MTA, so implementing it in cron would have been mostly a futile exercise.
On modern systems, there might be alternative choices, of course.
answered 14 hours ago
ilkkachuilkkachu
60.7k1098172
60.7k1098172
add a comment |
add a comment |
I assume that by "logging" you mean storing the actual output of jobs. The running of jobs is already logged in the cron log in /var/cron/log
(the path may differ between systems). There is no MTA required for this log.
A cron job is run as the user whose crontab the job is part of.
In the general case, there is no guarantee that this user is able to create files on the system (a user may not be an interactive user), especially not under the /var
hierarchy where logs are usually created. The safest way to notify the user of errors and other output from a job is therefore to collect these and send them by email to the user. This would also allow the user to set up email redirection for the account to be able to see e.g. errors in their preferred location.
If the user wants to save the output of a job to file, they may do so with a simple redirection in the crontab:
0 */2 * * * "$HOME/scripts/myscript" >"$HOME/logs/myscript.log" 2>&1
This would run "$HOME/scripts/myscript"
every second hour, on the hour, and would save all output to "$HOME/logs/myscript.log"
. No emails would be created by running this job as all output is redirected. Without the 2>&1
, error messages would still be sent by email.
This allows the user to choose where the output goes.
add a comment |
I assume that by "logging" you mean storing the actual output of jobs. The running of jobs is already logged in the cron log in /var/cron/log
(the path may differ between systems). There is no MTA required for this log.
A cron job is run as the user whose crontab the job is part of.
In the general case, there is no guarantee that this user is able to create files on the system (a user may not be an interactive user), especially not under the /var
hierarchy where logs are usually created. The safest way to notify the user of errors and other output from a job is therefore to collect these and send them by email to the user. This would also allow the user to set up email redirection for the account to be able to see e.g. errors in their preferred location.
If the user wants to save the output of a job to file, they may do so with a simple redirection in the crontab:
0 */2 * * * "$HOME/scripts/myscript" >"$HOME/logs/myscript.log" 2>&1
This would run "$HOME/scripts/myscript"
every second hour, on the hour, and would save all output to "$HOME/logs/myscript.log"
. No emails would be created by running this job as all output is redirected. Without the 2>&1
, error messages would still be sent by email.
This allows the user to choose where the output goes.
add a comment |
I assume that by "logging" you mean storing the actual output of jobs. The running of jobs is already logged in the cron log in /var/cron/log
(the path may differ between systems). There is no MTA required for this log.
A cron job is run as the user whose crontab the job is part of.
In the general case, there is no guarantee that this user is able to create files on the system (a user may not be an interactive user), especially not under the /var
hierarchy where logs are usually created. The safest way to notify the user of errors and other output from a job is therefore to collect these and send them by email to the user. This would also allow the user to set up email redirection for the account to be able to see e.g. errors in their preferred location.
If the user wants to save the output of a job to file, they may do so with a simple redirection in the crontab:
0 */2 * * * "$HOME/scripts/myscript" >"$HOME/logs/myscript.log" 2>&1
This would run "$HOME/scripts/myscript"
every second hour, on the hour, and would save all output to "$HOME/logs/myscript.log"
. No emails would be created by running this job as all output is redirected. Without the 2>&1
, error messages would still be sent by email.
This allows the user to choose where the output goes.
I assume that by "logging" you mean storing the actual output of jobs. The running of jobs is already logged in the cron log in /var/cron/log
(the path may differ between systems). There is no MTA required for this log.
A cron job is run as the user whose crontab the job is part of.
In the general case, there is no guarantee that this user is able to create files on the system (a user may not be an interactive user), especially not under the /var
hierarchy where logs are usually created. The safest way to notify the user of errors and other output from a job is therefore to collect these and send them by email to the user. This would also allow the user to set up email redirection for the account to be able to see e.g. errors in their preferred location.
If the user wants to save the output of a job to file, they may do so with a simple redirection in the crontab:
0 */2 * * * "$HOME/scripts/myscript" >"$HOME/logs/myscript.log" 2>&1
This would run "$HOME/scripts/myscript"
every second hour, on the hour, and would save all output to "$HOME/logs/myscript.log"
. No emails would be created by running this job as all output is redirected. Without the 2>&1
, error messages would still be sent by email.
This allows the user to choose where the output goes.
edited 14 hours ago
answered 15 hours ago
KusalanandaKusalananda
135k17255418
135k17255418
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505453%2fwhy-does-cron-require-mta-for-logging%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown