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
queuedefs(4)						     Kernel Interfaces Manual						      queuedefs(4)

NAME
queuedefs - Queue description file for at, batch, and cron commands DESCRIPTION
The queuedefs file describes the characteristics of the queues managed by cron or specifies other characteristics for cron. Each noncom- ment line in this file describes either one queue or a cron characteristic. Each uncommented line should be in one of the following for- mats. q.[njobj][nicen][nwaitw] max_jobs=mjobs log=lcode The fields in these lines are as follows: The name of the queue. Defined queues are as follows: The default queue for jobs started by at The default queue for jobs started by batch The default queue for jobs run from a crontab file Queues d to z are also available for local use. The maximum number of jobs that can be run simultaneously in the queue; if more than njob jobs are ready to run, only the first njob jobs will be run. The others will be initiated as currently running jobs ter- minate. The nice(1) value to give to all jobs in the queue that are not run with a user ID of superuser. The number of seconds to wait before rescheduling a job that was deferred because more than njob jobs were running in that queue, or because the system-wide limit of jobs executing (max_jobs) has been reached. The maximum number of active jobs from all queues that may run at any one time. The default is 25 jobs. Logging level of messages sent to a log file. The default is 4. Defined levels are as follows: level-code level 0 None 1 Low 2 Medium 3 High 4 Full Lines beginning with # are comments, and are ignored. EXAMPLES
The following file specifies that the b queue, for batch jobs, can have up to 50 jobs running simultaneously; that those jobs will be run with a nice value of 20. If a job cannot be run because too many other jobs are running, cron will wait 60 seconds before trying again to run it. All other queues can have up to 100 jobs running simultaneously; they will be run with a nice value of 2. If a job cannot be run because too many other jobs are running cron will wait 60 seconds before trying again to run it. b.50j20n60w The following file specifies that a total of 25 active jobs will be allowed by cron over all the queues at any one time, and cron will log all messages to the log file. The last two lines are comments that are ignored. max_jobs=25 log=4 # This is a comment # And so is this FILES
Main cron directory The default location for the queue description file. RELATED INFORMATION
Commands: at(1), cron(8), crontab(1), nice(1) delim off queuedefs(4)
All times are GMT -4. The time now is 09:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy