Operating System - Linux
1827808 Members
2028 Online
109969 Solutions
New Discussion

Re: getting specific cron dates

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

getting specific cron dates

Hello everyone,

our cronlog cron has over 700 jobs in the schedule, I want to find every job that starts after 20:00 on the server on a saturday.

possible strings= "*", "1-6" "5"

I have some idea how to do this but could someone suggest a solution please?

Thanks
hello
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor
Solution

Re: getting specific cron dates

Hi Lawrenzo:

Try this:

# cat ./sats
#!/usr/bin/perl -an
next if /\s*#/;
next unless $F[1]=~/20/ or $F[1] > 20 or $F[1] eq "\*";
next unless $F[4]=~/6/ or $F[4] eq "\*";
print;
1;

Run as:

# crontab -l | ./sats

This finds crontasks that are not commented-out; and are run on Saturday (day=6) or everyday of the week every hour, after 2000 hours or in a range including 2000 hours.

Note that Perl counts zero-relative. Hence, $F[1] is the *second* crontab field.

Regards!

...JRF...
lawrenzo_1
Super Advisor

Re: getting specific cron dates

Hi James,

Thanks for the help, I am not familiar with perl so unable to troubleshoot - here is the output:

--> crontab -l |./sats
+ ./sats
+ crontab -l
./sats[3]: next: not found.
./sats[4]: next: not found.
./sats[5]: next: not found.

./sats[7]: 1: 0403-006 Execute permission denied.

permissions are 777 on the file - owned and run by root
hello
spex
Honored Contributor

Re: getting specific cron dates

Lawrenzo,

Are you only interested in jobs running from 20:00 until 23:59 Saturday night, or are you also interested in some jobs which run early Sunday morning?

PCS
spex
Honored Contributor

Re: getting specific cron dates

Try this:

# crontab -l | ./sats

PCS
James R. Ferguson
Acclaimed Contributor

Re: getting specific cron dates

Hi (again) Lawrenzo:

Are you sure that your included the "shebang" (#!) line that declares the Perl interpreter?

You may need to change the location for Perl to match your server. Do:

# whereis perl
# which perl

Regards!

...JRF...
lawrenzo_1
Super Advisor

Re: getting specific cron dates

# which perl

/usr/bin/perl

and is the same in the script

any idea James?

Ty
hello
James R. Ferguson
Acclaimed Contributor

Re: getting specific cron dates

Hi Lawrenzo:

Well, if you cut-and-pasted the script I posted, there should only be six lines whereas the errors suggest that you have seven.

What do these show?

# ls -l /usr/bin/perl
# /usr/bin/perl -v

Regards!

...JRF...
lawrenzo_1
Super Advisor

Re: getting specific cron dates

Thanks for your help chaps,

James, muchas gracias - my issue was I copied your solution and pasted to my script however in my haste I managed to add # cat sats.

This works - brilliant!


Mr Law
hello