Operating System - HP-UX
1831390 Members
3046 Online
110025 Solutions
New Discussion

Script to list and mail crontab entries for all users in the server.

 
jaivinder
Frequent Advisor

Script to list and mail crontab entries for all users in the server.

Hi Gurus,

I our environment we have a lot of servers. I want to get the list of crontab file for each user emaild to me with full information.
Example:
In my server i have two crontab users root and oracle. I want the full details of all the crontab entries of both users. Can any one help me in this.


Thanks in advance.
6 REPLIES 6
Pete Randall
Outstanding Contributor

Re: Script to list and mail crontab entries for all users in the server.

Try this:

cat /var/spool/cron/crontab/*


Pete

Pete
Pete Randall
Outstanding Contributor

Re: Script to list and mail crontab entries for all users in the server.

Oops - missed the email part!

cat /var/spool/cron/crontabs/* |mail you@wherever.com


Pete

Pete
jaivinder
Frequent Advisor

Re: Script to list and mail crontab entries for all users in the server.

Thanks for you reply it helped me a lot. but i want it for every user and i want the script that can sort the working and non working crontab entries.
James R. Ferguson
Acclaimed Contributor

Re: Script to list and mail crontab entries for all users in the server.

Hi:

> I want the script that can sort the working and non working crontab entries.

If there is a file in '/var/spool/cron/crontabs' then there is a "working" crontab for that user. By "working" I mean that the 'cron' daemon will execute the script. Whether or not the executed script "works" is another matter.

Pete offered you a simple, straighforward solution. A simple embellishment would be to add the user to whom each crontab file belongs in the output.

Regards!

...JRF...
Steven E. Protter
Exalted Contributor

Re: Script to list and mail crontab entries for all users in the server.

Shalom,

write a report to a file and use:

http://www.hpux.ws/mailfile2 to mail the attachment.

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
Dennis Handly
Acclaimed Contributor

Re: Script to list and mail crontab entries for all users in the server.

>JRF: A simple embellishment would be to add the user to whom each crontab file belongs in the output.

That would be:
for file in /var/spool/cron/crontabs/*; do
user=${file##*/}
echo "crontab for user: $user ========="
cat $file
done | mailx -s "crontab list for $(hostname)" you@wherever.com