Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Edit crontab for basic utilities in a business setting System
Despite the handiness of Cronnix and other utils, I find that several factors promote the editing of crontab files for use in corporate settings:
  1. Freeware or shareware is often discouraged.
  2. Potential conflicts with other apps, utils or OS X upgrades is higher with free/shareware apps than with crontab running additional diskutil or plutil jobs.
  3. Without running a scheduler like iBeezz that will wake systems up and run specific jobs, sleeping systems will wake and run utils at the worst time for users -- when they are trying to start work.
So here's a sample crontab that changes the daily, weekly, and monthly jobs to run at a time when systems are (hopefully) not asleep (our builds wait three hours before they sleep). repairPermissions is run weekly, as is plutil's preferences check both for User and System-level prefs. I'm no UNIX guru so feel free to correct any errors, but this crontab runs well on 100+ production OS 10.3.3-5 systems.
# /etc/crontab
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
HOME=/var/log
#
#minute  hour  mday  month  wday  who  command
#
#*/5  *  *  *  *  root  /usr/libexec/atrun
#
# Run daily/weekly/monthly jobs.
# Modified by YOURNAMEHERE for XCORP, DATE. 
# Adds weekly Repair Permissions plus reschedules periodic jobs
# for times when systems are running and awake.
# Adds weekly prefs scan, -s reports only corrupt prefs.
15  17  *  *  *  root  periodic daily
30  9   *  *  2  root  periodic weekly
30  10  1  *  *  root  periodic monthly
15  18  *  *  3  root  diskutil repairPermissions /
15  16  *  *  4  root  plutil -s ~/Library/Preferences/*.plist
30  16  *  *  4  root  plutil -s /Library/Preferences/*.plist
[robg adds: I haven't tested this one, but I do understand the business perspective -- untested external tools aren't particularly welcome at my office, either! If you try this, you'll want to use tabs between the items in the crontab list; they're spaces here to make it a bit narrower.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[9,588 views]  

Edit crontab for basic utilities in a business setting | 7 comments | Create New Account
Click here to return to the 'Edit crontab for basic utilities in a business setting' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Edit crontab for basic utilities in a business setting
Authored by: spot on Feb 11, '05 01:47:57PM

Just to clarify, there are two "crontabs":

1) The command line utility crontab, which is a tool to edit crontab files.
2) The system crontab file which is /etc/crontab

Apart from the system crontab file, each user has a crontab file, located in /var/cron/tabs.

These files are executed on schedule by the system daemon cron.

CronniX is not a replacement cron utility, it's merely tool to edit the crontab files.



[ Reply to This | # ]
Edit crontab for basic utilities in a business setting
Authored by: sheurich on Feb 11, '05 03:20:47PM

The lines that read :

15 16 * * 4 root plutil -s ~/Library/Preferences/*.plist
30 16 * * 4 root plutil -s /Library/Preferences/*.plist

should be changed. The first line uses ~, which expands to /private/var/root, since this is being run by root - assuming you are trying to check your own Preferences you will want to replace this by ~username.

A more complete solution would be :

15 16 * * 4 root find /Library/Preferences /Users/*/Library/Preferences -name \*.plist -exec plutil -s {} \;

This will check the local system's library as well as all local users' libraries for proper syntax of property lists.

To add root's library as well (which is probably not necessary, unless you are logging in to the console as root) :

15 16 * * 4 root find /Library/Preferences /Users/*/Library/Preferences /private/var/root/Library/Preferences -name \*.plist -exec plutil -s {} \;



[ Reply to This | # ]
Edit crontab for basic utilities in a business setting
Authored by: thornezilla on Feb 11, '05 06:49:08PM

Thanks for the correction -- yes, having plutil check the "~/Library" doesn't do a whole lot of good since it fails to check any of the users' Preferences directories. The system crontab is being run as root while the computers are either showing the login screen, or logged-in as various non-Admin users.

What our local UNIX guru pointed out to me is that running the plutil in this fashion doesn't do much good, as any failures are not visible to the users and generate no reports.

He suggests that I have any failures trigger an AppleScript that removes the offending plist files. At the very least, errors need to call a dialog box up to let the user know that there is a damaged pref file at location: "Users/xxxx/Library/Preferences/xxxx.plist".



[ Reply to This | # ]
Edit crontab for basic utilities in a business setting
Authored by: DanFrakes on Feb 13, '05 02:05:39AM

"The system crontab is being run as root while the computers are either showing the login screen, or logged-in as various non-Admin users."

To be clear, the system crontab is *always* run as root -- even if an admin user is logged in.


"What our local UNIX guru pointed out to me is that running the plutil in this fashion doesn't do much good, as any failures are not visible to the users and generate no reports."

Right. You can mail the results or even pipe them to a text file on a server or to a particular account's Desktop. This way an admin or the user, respectively, could check the outputs for problems.



[ Reply to This | # ]
Cron output is mailed to user
Authored by: surf on Feb 12, '05 02:40:25PM

Hmm, usually, any output from scripts run by cron should be automatically mailed to the owner of the crontab (or the one specified in MAILTO in the crontab).



[ Reply to This | # ]
anacron, cron helper for boxes that do not run 24/7
Authored by: surf on Feb 12, '05 02:50:28PM

A better way than to guess the time a box will be running is to install anacron. It will check if a cron script has run or if the box was turned off at this time.

It can do this delayed on system startup. Also you can always use "nice" to give the cronjobs a lower priority so they don't trash the system too much.

BTW: The remark about freeware is kind of strange, if you consider the nature of Darwin, Apache, Samba etc.



[ Reply to This | # ]
Edit crontab for basic utilities in a business setting
Authored by: kurizaemon on May 18, '05 06:17:56PM

1. Freeware or shareware is often discouraged.

Umm ... Cron (and crontab) is freeware! I know you paid for the copy you got in OSX, and that's cool - I did too. Still, rather funny to see this in an article about crontab :)

Understand you're talking about Cronnix here, but really both apps are free; the difference is that one came to you on an Apple CD and is vendor supported, and the other is a third-party download.

Am I being too picky here? I guess this really meant, "Third-party freeware/shareware is discouraged."



[ Reply to This | # ]