Operating System - HP-UX
1837921 Members
6974 Online
110124 Solutions
New Discussion

Anybody write script (ksh) to report crontab entries ?

 
Daniel Sidwell
New Member

Anybody write script (ksh) to report crontab entries ?

Hi,

I shearch a script to report entries of the crontabs file, sort by schedule.

By example I would like to know every day what will be execute in my box from 17:00 today until 16:59 tomorrow, all order by time.

It is dificult for me to interpret all the caractere of the crontal file, by example
I can find, *, -, numbers etc... I know the format and signification of the record but I would like to make un report easyer to read for a non unix person. I start to write the script but I have difficulties to program the script to read and interpret the schedule.

regards
Administrateur Unix de Quebec.
9 REPLIES 9
RAC_1
Honored Contributor

Re: Anybody write script (ksh) to report crontab entries ?

May be this will work.

crontab -l|sort -rnk5|sort -rnk4|sort -rnk3|sort -rnk2|sort -rnk1

Anil

There is no substitute to HARDWORK
RAC_1
Honored Contributor

Re: Anybody write script (ksh) to report crontab entries ?

May be this will work.

crontab -l user_name |sort -rnk5|sort -rnk4|sort -rnk3|sort -rnk2|sort -rnk1

Anil
There is no substitute to HARDWORK
Rodney Hills
Honored Contributor

Re: Anybody write script (ksh) to report crontab entries ?

I have attached a "perl" script that generates a graphical chart of jobs by the hour.

It may be not what you are looking for, but I needed a way to visualize what jobs were running in parallel with other jobs.

For each job from crontab I add a line into the script that has the day ranges (SMTWUFS), the start hour/minute, and the end hour/minute.

Then the script dumps out a a chart showing all the jobs and the time range they are running. Since our jobs start before midnight I had to take in account the time roll over.

Maybe with a little editting you can find use for it...

HTH

-- Rod Hills
There be dragons...
Daniel Sidwell
New Member

Re: Anybody write script (ksh) to report crontab entries ?

Thanks to RAC and Rodney Hills for the awnser. For the moment I can't assign points because I don't know how, it's the first intervention on this forum. I read documentation about this and I will quote later if I can. Thanks again.

I have another question for Rodney.

I think you understand what I need but I studie and practice a lot of programming language, like PLI, fortran, cobol, basic, apl etc but I forget it. Now I am fluently in korn shell and I don't know nothing about Perl.

What I need to run your script on my box. Do I have to install some fileset to have the interpreter of Perl who can understand your script ?

thanks in advance
Administrateur Unix de Quebec.
Rodney Hills
Honored Contributor

Re: Anybody write script (ksh) to report crontab entries ?

If you are on hpux 11.00 or above you may already have perl. Enter "perl -v" to see, or do a "ls -d /opt/perl*" to see if you have it.

If you don't then you can get it from the porting center-
http://hpux.cs.utah.edu/hppd/hpux/Languages/perl-5.8.3/

perl brings the benefit of shell scripting, grep, awk, sed all into one spiffy programming language. It has been called the system administrators "glue" language. Documentation can be found all over the internet.

HTH

-- Rod Hills
There be dragons...
Geoff Wild
Honored Contributor

Re: Anybody write script (ksh) to report crontab entries ?

Yes, you need perl installed:

http://www.software.hp.com/portal/swdepot/displayProductInfo.do?productNumber=PERL

It may already be there:

# which perl

/usr/bin/perl

# ll /usr/bin/perl
lrwxr-xr-x 1 root sys 18 May 7 13:06 /usr/bin/perl -> /opt/perl/bin/perl


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Daniel Sidwell
New Member

Re: Anybody write script (ksh) to report crontab entries ?

Thanks Rodney,

I verifie if i have perl on my box.
When I type this command :
# perl -v

I received this anwser :

This is perl, version 4.0

$RCSfile: perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $
Patch level: 36

Copyright (c) 1989, 1990, 1991, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 4.0 source kit.

But when I execute the command :

# perl -c testcron.pl

NB testcron.pl is the script then I downlaod from your previous answer.

I have this anwser

the flag minus c meaning testing the syntax of the script

syntax error in file testcron.pl at line 5, next 2 tokens "(["
syntax error in file testcron.pl at line 21, next 2 tokens "(["
syntax error in file testcron.pl at line 26, next 2 tokens "]["
syntax error in file testcron.pl at line 28, next 2 tokens "]["
syntax error in file testcron.pl at line 46, next token "}"
syntax error in file testcron.pl at line 49, next 2 tokens "++)"
syntax error in file testcron.pl at line 59, next 2 tokens "++)"
syntax error in file testcron.pl at line 74, next token "}"
syntax error in file testcron.pl at line 108, next 2 tokens "]["
testcron.pl had compilation errors.

If I execute this command

# perl testcron.pl

I received the same last awnser.

I explore the perl world for the fist time

sorry for my inexperience with that.

thanks again.
Administrateur Unix de Quebec.
Rodney Hills
Honored Contributor

Re: Anybody write script (ksh) to report crontab entries ?

You have perl4 (which is outdated). Fetch perl5 from the URL above. perl had some major changes from 4 to 5

HTH

-- Rod Hills
There be dragons...
Daniel Sidwell
New Member

Re: Anybody write script (ksh) to report crontab entries ?

Hi Rodney,

I have installed the version of Perl that I found on CD number 4 of the applications cd of dec 2003 and I can run your script without any problem.

Your script make a great job but when I examine this script I can understand that this script doesn't read the crontab file, all the cron are coded at the beginning of the script.

This script doesn't take care of the * and - and , that I can found in the crontab file. But your script is very interressant and I am sure it will be helpful for me.

Thanks a lot for your help.

Have a nice day.
Administrateur Unix de Quebec.