.\"
.\" $Id: cron.8,v 1.8 2004/01/23 19:03:32 vixie Exp $
.\"
-.TH CRON "8" "July 2009" "Marcela Mašláňová" "Cronie Users' Manual"
+.TH CRON "8" "December 2009" "Marcela Mašláňová" "Cronie Users' Manual"
.SH NAME
cron \- daemon to execute scheduled commands
.SH SYNOPSIS
.B cron
-.RB [ -n " | " -p " | " -m \fP\fI<mail command>\fP\fB ]
+.RB [ -n " | " -p " | " -s " | " -m \fP\fI<mail command>\fP\fB ]
.br
.B cron
.B -x
run in the current minute. When executing
commands, any output is mailed to the owner of the crontab (or to the user
named in the MAILTO environment variable in the crontab, if such exists).
+Job output can also be sent to syslog by using the
+.B "\-s"
+option.
.PP
There are two ways, how the changes are checked in crontables. The first
is checking the modtime of file and the other is using inotify support.
can be overriden by settings in the appropriate crontab file.
.SH "OPTIONS"
.TP
+.B "\-s"
+This option will direct cron to send job output to the system log using
+.IR syslog (3).
+This is useful if your system has no
+.BR sendmail (8).
+.TP
.B "\-m"
This option allows you to specify a shell command string to use for sending cron mail
output instead of
static void usage(void) {
const char **dflags;
- fprintf(stderr, "usage: %s [-n] [-p] [-i] [-m <mail command>] [-x [",
+ fprintf(stderr, "usage: %s [-n] [-p] [-s] [-i] [-m <mail command>] [-x [",
ProgramName);
for (dflags = DebugFlagNames; *dflags; dflags++)
fprintf(stderr, "%s%s", *dflags, dflags[1] ? "," : "]");
setlinebuf(stderr);
#endif
+ SyslogOutput = 0;
NoFork = 0;
parse_args(argc, argv);
static void parse_args(int argc, char *argv[]) {
int argch;
- while (-1 != (argch = getopt(argc, argv, "npix:m:"))) {
+ while (-1 != (argch = getopt(argc, argv, "npsix:m:"))) {
switch (argch) {
default:
usage();
case 'p':
PermitAnyCrontab = 1;
break;
+ case 's':
+ SyslogOutput = 1;
+ break;
case 'i':
DisableInotify = 1;
break;
int children = 0;
char **jobenv = 0L;
pid_t pid = getpid();
+ pid_t jobpid;
/* Set up the Red Hat security context for both mail/minder and job processes:
*/
/* fork again, this time so we can exec the user's command.
*/
- switch (fork()) {
+ switch ((jobpid = fork())) {
case -1:
log_it("CRON", pid, "can't fork", "child_process", errno);
cron_close_pam();
FILE *mail = NULL;
int bytes = 1;
int status = 0;
+#if defined(SYSLOG)
+ char jobtag[64], logbuf[1024];
+ int bufidx = 0;
+ /* according to the NOTES section of openlog(3), jobtag will be
+ * used (implicitly) by future calls to syslog(). That's why it
+ * was defined outside of the if block here. */
+ if (SyslogOutput) {
+ snprintf(jobtag, sizeof(jobtag), "CROND[%d]", jobpid);
+ openlog(jobtag, 0, LOG_CRON);
+ if (ch != '\n')
+ logbuf[bufidx++] = ch;
+ }
+#endif
Debug(DPROC | DEXT,
("[%ld] got data (%x:%c) from grandchild\n",
if (mail)
putc(ch, mail);
}
+#if defined(SYSLOG)
+ if (SyslogOutput) {
+ logbuf[bufidx++] = ch;
+ if ((ch == '\n') || (bufidx == sizeof(logbuf)-1)) {
+ if (ch == '\n')
+ logbuf[bufidx-1] = '\0';
+ else
+ logbuf[bufidx] = '\0';
+ syslog(LOG_INFO, "%s", logbuf);
+ bufidx = 0;
+ }
+ }
+#endif
/* only close pipe if we opened it -- i.e., we're
* mailing...
*/
status = cron_pclose(mail);
}
+#if defined(SYSLOG)
+ if (SyslogOutput) {
+ if (bufidx) {
+ logbuf[bufidx] = '\0';
+ syslog(LOG_INFO, "%s", logbuf);
+ }
+ closelog();
+ }
+#endif
/* if there was output and we could not mail it,
* log the facts so the poor user can figure out
XTRN char *ProgramName;
XTRN int LineNumber;
+XTRN int SyslogOutput;
XTRN time_t StartTime;
XTRN int NoFork;
XTRN int PermitAnyCrontab;