Sponsored Content
Full Discussion: How to read cron log ?
Top Forums UNIX for Advanced & Expert Users How to read cron log ? Post 302956419 by MadeInGermany on Tuesday 29th of September 2015 04:53:30 PM
Old 09-29-2015
A cron delegation

While sudo might suit best here, I present another method of delegation.

Add these root crontab entries
Code:
47 * * * * /usr/bin/run-parts -l /var/log/run-parts.log /etc/cron.d/hourly
40 4 * * * /usr/bin/run-parts -l /var/log/run-parts.log /etc/cron.d/daily
30 4 * * 0 /usr/bin/run-parts -l /var/log/run-parts.log /etc/cron.d/weekly
20 4 1 * * /usr/bin/run-parts -l /var/log/run-parts.log /etc/cron.d/monthly

Prepare directories by
Code:
mkdir -p /etc/cron.d/hourly /etc/cron.d/daily /etc/cron.d/weekly /etc/cron.d/monthly
mkdir -p /var/log

Install the executable /usr/bin/run-parts script
Code:
#!/bin/sh
# run-parts:  Runs all the scripts found in a directory.

# keep going when something fails
set +e
# ensure wild card matching
set +f

if [ x"$1" = x"-l" ]; then
  logfile=$2
  shift 2
fi

if [ $# -lt 1 ]; then
  echo "Usage: run-parts [-l logfile] <directory>"
  exit 1
fi

if [ ! -d "$1" ]; then
  echo "Not a directory: $1"
  exit 1
fi

umask 22

if [ -n "$logfile" ]; then
# rotate if >10MB
  [ -f "$logfile" ] && find "$logfile" -size +20000 -exec mv "$logfile" "$logfile.old" \;
  exec >> "$logfile" 2>&1 || exit
fi

# an individual pause:
sleep `cksum /etc/hosts | awk '{print $1'\%'60}'`

# Main loop:
for SCRIPT in "$1"/* ; do
# There are several types of files that we would like to
# ignore automatically, as they are likely to be backups
# of other scripts:
  case $SCRIPT in
  *.bak|*.new|*.old|*.orig|*.swp)
    continue # the loop
    ;;
  *[a-zA-Z0-9])
# The last character is legal :-)
    ;;
  *)
    continue # the loop
    ;;
  esac
# If we've made it this far, then run the script if it's executable:
  if [ -f "$SCRIPT" -a -x "$SCRIPT" ]; then
    echo "`date` run $SCRIPT":
    "$SCRIPT"
    echo
  fi
done

exit 0

Now add your executable script to /etc/cron.d/weekly, for weekly execution.
Its output is logged to /var/log/run-parts.log.
You can put more than one script to any of the hourly daily weekly monthly directories.
It works like the /etc/cron.*ly/ in Linux.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

adding date to cron log

Hi. I'm trying to output the current date to a cronjob log file. Nothing seems to work, echo $(date), echo `date` or just date in the script. I'm using /sbin/sh Any ideas? Thanks, John (2 Replies)
Discussion started by: JohnH
2 Replies

2. UNIX for Dummies Questions & Answers

Cron log entries

Hi, I am confused with the entries in my cron log, I'm not sure what exactly these commands are doing, any body can show me the way to get understanding of what these entries mean:> CMD: $TFADMIN /usr/lib/uucp/uudemon.poll > /dev/null > CMD: $TFADMIN /usr/lib/uucp/uudemon.hour > /dev/null > ... (1 Reply)
Discussion started by: nervous
1 Replies

3. AIX

AIX and cron logs filtering ?: /etc/cronlog.conf, /var/adm/cron/log

Hi, I can use 'crontabs –e' and do all the scheduling I like. However I would like to auto send myself just the cronjobs logs that fail. That is to say the PIDs that fail and the related lines with those PID’s only. (Not the full set of logs) Has anyone done this work? Or does an AIX 5.3 tool... (0 Replies)
Discussion started by: Keith Johnson
0 Replies

4. UNIX for Dummies Questions & Answers

Regarding Cron log creation

Cameron, I have deleted the cron log file and create a new cron log file as the older was sucking up the disk space. now i have rescheduled the cron job but i dont see any logs on the newly created log file. I am confused what has happened. Can u help me out on this. (0 Replies)
Discussion started by: sanei05
0 Replies

5. Shell Programming and Scripting

cron job issue..i hav read the basic threads already...

hi friends well m facing a different sort of issue in my cron. i hav set job like this 30 09 * * 1 /bin/backup14M 01 14 * * 1 /bin/backup14N 20 18 * * 1 /bin/backup14E that is for every Monday at three different times. but, first job executes well, later ones do not. I checked my... (13 Replies)
Discussion started by: oracle.test2
13 Replies

6. UNIX for Dummies Questions & Answers

How to change the log level for cron?

Hello, I'm wondering how to change the log level to level 2 for cron without manually have to restart it with every boot. I didn't thing this would be hard to find, but searching has cause me to come up empty. System is Ubuntu Karmic/9.10 With thanks, Narnie (6 Replies)
Discussion started by: Narnie
6 Replies

7. Shell Programming and Scripting

Cron Log file

Hi Iam new to unix .please help me in writing a script.Suppose there are 100 scripts in a cron file which are scheduled to run at different times,different dates . I need to monitor all the scripts daily whether they ran or not if ran whether its sucessfully ran or not . if the script hasnt... (2 Replies)
Discussion started by: mskalyani
2 Replies

8. Shell Programming and Scripting

How to read log files from last read

Hi i am looking a way to look at a log file(log.txt) from the last time I've read it. However after some days the main log file(log.txt) is rename to (log.txt.1). So now i will have two log files as below. log.txt.1 log.txt Now, i have to read the log from the point where i have left... (3 Replies)
Discussion started by: sumitsks
3 Replies

9. UNIX for Dummies Questions & Answers

How are cron.allow and cron.deny read?

Hi, all! I was working on my Debian, minding my own business but then I wanted to see what happened if the same user was included on both cron.allow and cron.deny :p I would have bet that cron.deny was going to override cron.allow for security reasons, but my computer proved me wrong:... (3 Replies)
Discussion started by: pereyrax
3 Replies

10. Solaris

Log error from cron job into log file

Hi Please would it be right to log the errors from a script running in cron in the following manner: /datax/vendor/dump.sh > /datax/vendor/err.log 2>&1 (16 Replies)
Discussion started by: fretagi
16 Replies
CRON(8) 						      System Manager's Manual							   CRON(8)

NAME
cron - daemon to execute scheduled commands (Vixie Cron) SYNOPSIS
cron [-f] [-l] [-L loglevel] DESCRIPTION
cron is started automatically from /etc/init.d on entering multi-user runlevels. OPTIONS
-f Stay in foreground mode, don't daemonize. -l Enable LSB compliant names for /etc/cron.d files. This setting, however, does not affect the parsing of files under /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly or /etc/cron.monthly. -L loglevel Tell cron what to log about jobs (errors are logged regardless of this value) as the sum of the following values: 1 will log the start of all cron jobs 2 will log the end of all cron jobs 4 will log all failed jobs (exit status != 0) 8 will log the process number of all cron jobs The default is to log the start of all jobs (1). Logging will be disabled if levels is set to zero (0). A value of fifteen (15) will select all options. NOTES
cron searches its spool area (/var/spool/cron/crontabs) for crontab files (which are named after accounts in /etc/passwd); crontabs found are loaded into memory. Note that crontabs in this directory should not be accessed directly - the crontab command should be used to access and update them. cron also reads /etc/crontab, which is in a slightly different format (see crontab(5)). In Debian, the content of /etc/crontab is prede- fined to run programs under /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly and /etc/cron.monthly. This configuration is specific to Debian, see the note under DEBIAN SPECIFIC below. in order 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. Like /etc/crontab, the files in the /etc/cron.d directory are monitored for changes. In general, the system administrator should not use /etc/cron.d/, but use the standard system crontab /etc/crontab. /etc/crontab and the files in /etc/cron.d must be owned by root, and must not be group- or other-writable. In contrast to the spool area, the files under /etc/cron.d or the files under /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly and /etc/cron.monthly may also be sym- links, provided that both the symlink and the file it points to are owned by root. The files under /etc/cron.d do not need to be exe- cutable, while the files under /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly and /etc/cron.monthly do, as they are run by run-parts (see run-parts(8) for more information). cron then wakes up every minute, examining all stored crontabs, checking each command to see if it should be 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). The children copies of cron running these processes have their name coerced to uppercase, as will be seen in the syslog and ps output. Additionally, cron checks each minute to see if its spool directory's modtime (or the modtime on the /etc/crontab file) has changed, and if it has, cron will then examine the modtime on all crontabs files and reload those which have changed. Thus cron need not be restarted whenever a crontab file is modified. Note that the crontab(1) command updates the modtime of the spool directory whenever it changes a crontab. Special considerations exist when the clock is changed by less than 3 hours, for example at the beginning and end of daylight savings time. If the time has moved forwards, those jobs which would have run in the time that was skipped will be run soon after the change. Con- versely, if the time has moved backwards by less than 3 hours, those jobs that fall into the repeated time will not be re-run. Only jobs that run at a particular time (not specified as @hourly, nor with '*' in the hour or minute specifier) are affected. Jobs which are specified with wildcards are run based on the new time immediately. Clock changes of more than 3 hours are considered to be corrections to the clock, and the new time is used immediately. cron logs its action to the syslog facility 'cron', and logging may be controlled using the standard syslogd(8) facility. ENVIRONMENT
If configured in /etc/default/cron in Debian systems, the cron daemon localisation settings environment can be managed through the use of /etc/environment or through the use of /etc/default/locale with values from the latter overriding values from the former. These files are read and they will be used to setup the LANG, LC_ALL, and LC_CTYPE environment variables. These variables are then used to set the charset of mails, which defaults to 'C'. This does NOT affect the environment of tasks running under cron. For more information on how to modify the environment of tasks, consult crontab(5) The daemon will use, if present, the definition from /etc/timezone for the timezone. The environment can be redefined in user's crontab definitions but cron will only handle tasks in a single timezone. DEBIAN SPECIFIC
Debian introduces some changes to cron that were not originally available upstream. The most significant changes introduced are: -- Support for /etc/cron.{hourly,daily,weekly,monthly} via /etc/crontab, -- Support for /etc/cron.d (drop-in dir for package crontabs), -- PAM support, -- SELinux support, -- auditlog support, -- DST and other time-related changes/fixes, -- SGID crontab(1) instead of SUID root, -- Debian-specific file locations and commands, -- Debian-specific configuration (/etc/default/cron), -- numerous other smaller features and fixes. Support for /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly and /etc/cron.monthly is provided in Debian through the default setting of the /etc/crontab file (see the system-wide example in crontab(5)). The default sytem-wide crontab contains four tasks: run every hour, every day, every week and every month. Each of these tasks will execute run-parts providing each one of the directories as an argument. These tasks are disabled if anacron is installed (except for the hourly task) to prevent conflicts between both daemons. As described above, the files under these directories have to be pass some sanity checks including the following: be executable, be owned by root, not be writable by group or other and, if symlinks, point to files owned by root. Additionally, the file names must conform to the filename requirements of run-parts: they must be entirely made up of letters, digits and can only contain the special signs underscores ('_') and hyphens ('-'). Any file that does not conform to these requirements will not be executed by run-parts. For example, any file containing dots will be ignored. This is done to prevent cron from running any of the files that are left by the Debian package management system when handling files in /etc/cron.d/ as configuration files (i.e. files ending in .dpkg-dist, .dpkg-orig, and .dpkg-new). This feature can be used by system administrators and packages to include tasks that will be run at defined intervals. Files created by packages in these directories should be named after the package that supplies them. Support for /etc/cron.d is included in the cron daemon itself, which handles this location as the system-wide crontab spool. This direc- tory can contain any file defining tasks following the format used in /etc/crontab, i.e. unlike the user cron spool, these files must pro- vide the username to run the task as in the task definition. Files in this directory have to be owned by root, do not need to be executable (they are configuration files, just like /etc/crontab) and must conform to the same naming convention as used by run-parts(8): they must consist solely of upper- and lower-case letters, digits, underscores, and hyphens. This means that they cannot contain any dots. If the -l option is specified to cron (this option can be setup through /etc/default/cron, see below), then they must conform to the LSB namespace specification, exactly as in the --lsbsysinit option in run-parts. The intended purpose of this feature is to allow packages that require finer control of their scheduling than the /etc/cron.{hourly,daily,weekly,monthly} directories to add a crontab file to /etc/cron.d. Such files should be named after the package that supplies them. Also, the default configuration of cron is controlled by /etc/default/cron which is read by the init.d script that launches the cron dae- mon. This file determines whether cron will read the system's environment variables and makes it possible to add additional options to the cron program before it is executed, either to configure its logging or to define how it will treat the files under /etc/cron.d. SEE ALSO
crontab(1), crontab(5), run-parts(8) AUTHOR
Paul Vixie <paul@vix.com> is the author of cron and original creator of this manual page. This page has also been modified for Debian by Steve Greenland, Javier Fernandez-Sanguino and Christian Kastner. 4th Berkeley Distribution 19 April 2010 CRON(8)
All times are GMT -4. The time now is 05:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy