Operating System - Linux
1754296 Members
2918 Online
108813 Solutions
New Discussion юеВ

Command to display all crontabs for a given system

 
SOLVED
Go to solution
Dave Falloon
Trusted Contributor

Command to display all crontabs for a given system

I am looking for a command that would show all of the active installed crontabs for all users on a machine. Is there a more elegant way than ls in /var/spool/cron/crontabs/ ?

Are the crontabs shown in that directory necessarily active?

Thanks,

Dave
Clothes make the man, Naked people have little to no effect on society
5 REPLIES 5
Steven E. Protter
Exalted Contributor
Solution

Re: Command to display all crontabs for a given system

crontab -l

But that only works for each user.

You can do a su - username -c "crontab -l" for each user authorized for cron.

Or you can look at the raw files.

watch this.



while xx
read
cron.allow
/usr/bin/su - $xx -c "crontab -l"
done < /var/adm/cron/cron.allow

That will do it.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Steven E. Protter
Exalted Contributor

Re: Command to display all crontabs for a given system

My instructions were HP-UX specific and did not read your question carefully.

If you change the script I wrote to /var/spool/cron it will display the crontabs.

I know of know more elegant way to do the job.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Huc_1
Honored Contributor

Re: Command to display all crontabs for a given system

I have written and tested a small sh script on Linux that does it in a different way

"All the road lead to Rome"

To try it out just download the attachement invoke it as root like

./show_all_crontab.sh

should do the job of diplaying the content of th various crontabs, you could output this to a report file like

ex:

#./show_all_crontab.sh > report_crontab.rep

then when you need to check if it as been modified you could

ex:
# mv report_crontab.rep report_crontab_old.rep
# ./show_all_crontab.sh > report_crontab.rep
# diff report_crontab_old.rep report_crontab.rep

this way you would know WHAT has been changed.

If you are more intested by WHEN it has been changed then you could do

ex:

#for i in `find /var/spool/cron/ -name "*" -type f` ; do stat $i ; done > when_change_crontab.rep

this when_change_crontab.rep could also be mv to an old version when needed and checked again's difference's with newly created when_change_crontab.rep


all theses ex: could be put into a script invoke so to make it more robust and easy.

Hope this will get you rolling

Keep us informed.

enjoy

J-P

Smile I will feel the difference
Huc_1
Honored Contributor

Re: Command to display all crontabs for a given system

Me again.. try to be short this time around

It is just say the I named attachement script show_all_crontab.sh
the forums rename's it to 14807.sh

so remplace show_all_crontab.sh with 14807.sh in my prior reply.

J-P
Smile I will feel the difference
Dave Falloon
Trusted Contributor

Re: Command to display all crontabs for a given system

Thanks Guys,

Thats pretty much what I figured though, its not a hidden cron switch from 1975 or something that has just been left out of the man pages.

SEP you get points for fast command line job, but I think huc wins as far as script features :)

Again thanks a lot guys,

Dave
Clothes make the man, Naked people have little to no effect on society