LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   CentOS 7: How to list completed cron jobs? (https://www.linuxquestions.org/questions/linux-newbie-8/centos-7-how-to-list-completed-cron-jobs-4175603613/)

fanoflq 04-11-2017 01:38 AM

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?

descendant_command 04-11-2017 01:50 AM

Code:

# grep CRON /var/log/syslog
or equivalent.

fanoflq 04-11-2017 02:20 AM

Solved!
Quote:

/var/log/cron

JJJCR 04-11-2017 04:10 AM

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

vincix 04-11-2017 04:57 AM

Quote:

Originally Posted by JJJCR (Post 5695480)
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?

fanoflq 04-11-2017 12:38 PM

Quote:

Originally Posted by JJJCR (Post 5695480)
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?

JJJCR 04-17-2017 02:33 AM

Quote:

Originally Posted by vincix (Post 5695488)
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.

JJJCR 04-17-2017 04:19 AM

Quote:

Originally Posted by fanoflq (Post 5695662)
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

vincix 04-17-2017 02:17 PM

Quote:

Originally Posted by JJJCR (Post 5697939)
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.


All times are GMT -5. The time now is 12:41 PM.