LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-11-2017, 12:38 AM   #1
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Rep: Reputation: Disabled
CentOS 7: How to list completed cron jobs?


It there a way to list jobs that has been
executed by cron or anacron in CentOS7 for
a given period of time, e.g. last 24 hours?
 
Old 04-11-2017, 12:50 AM   #2
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,876

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Code:
# grep CRON /var/log/syslog
or equivalent.
 
Old 04-11-2017, 01:20 AM   #3
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Solved!
Quote:
/var/log/cron
 
Old 04-11-2017, 03:10 AM   #4
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
This has been solved but if someone would came across with same issue try something like this:

Quote:
sed -n '/Apr 10 00:00:01/ , /Apr 11 00:01:01/p' /var/log/cron

Last edited by JJJCR; 04-11-2017 at 03:10 AM. Reason: edit
 
2 members found this post helpful.
Old 04-11-2017, 03:57 AM   #5
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
Quote:
Originally Posted by JJJCR View Post
This has been solved but if someone would came across with same issue try something like this:
Good idea, but what if cron wasn't executed at that particular hour of the day?
 
Old 04-11-2017, 11:38 AM   #6
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by JJJCR View Post
This has been solved but if someone would came across with same issue try something like this:
How do you use awk to do a lines range
search instead of sed for above?
 
Old 04-17-2017, 01:33 AM   #7
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Cool

Quote:
Originally Posted by vincix View Post
Good idea, but what if cron wasn't executed at that particular hour of the day?
I guess you can adjust the time range, but more specific time will get specific result. Log file can be very big, if the output is quite long then it's quite difficult to see or check.
 
Old 04-17-2017, 03:19 AM   #8
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Smile

Quote:
Originally Posted by fanoflq View Post
How do you use awk to do a lines range
search instead of sed for above?
Try something like this:

awk '/(Apr 10 00:00:01)/ { print $0 }' /var/log/cron

Please see links below:
http://quickbytesstuff.blogspot.sg/2...-tutorial.html

http://quickbytesstuff.blogspot.sg/2...e-example.html
 
Old 04-17-2017, 01:17 PM   #9
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
Quote:
Originally Posted by JJJCR View Post
I guess you can adjust the time range, but more specific time will get specific result. Log file can be very big, if the output is quite long then it's quite difficult to see or check.
That's not the point. The problem is that if there are no logs at "/Apr 10 00:00:01/", then absolutely nothing will show up. Moreover, if there are no logs at 'Apr 11 00:01:01', then all lines will show up until there are no more lines in the log. Not really nice.

I had been looking for the same answer for a while. I guess one solution would be to simply do grep for the day you're interested and then pipe it into awk:
grep "Apr 10" | awk -F '[ :]' '$3 >= 15 && $4 >= 30 { print $0 }' - which is going to print all logs starting from 3:30 PM on April 10, even if there is are no logs at exactly 3:30.


As far as your second solution is concerned "awk '/(Apr 10 00:00:01)/ { print $0 }' /var/log/cron)", I really don't understand what you're trying to do. That will only print the lines containing "Apr 10 00:00:01". I don't see the point. He was asking about a line range.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron job starts 6 hours late, rest of cron jobs work fine pieterhouwen Linux - Newbie 33 10-05-2015 12:38 PM
LXer: perform cron jobs redundancy using rcron on centos rhel debian ubuntu fedora LXer Syndicated Linux News 0 06-11-2013 01:00 PM
[SOLVED] Centos 6.2 Cron Jobs jeffreydavisjr Linux - Server 8 03-20-2012 01:01 PM
Centos 6 don't run my cron jobs ASTRAPI Linux - Server 2 01-15-2012 01:42 AM
CUPS - Completed Jobs AlanSecker Linux - Desktop 3 12-31-2006 12:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration