AFP548

Better periodic maintenance

This solves a problem with laptops (and/or desktops) being on again off again and perhaps missing the absolute time of the cron jobs run via periodic (daily, weekly, monthly).Problem: ensuring that the daily/weekly/monthly maintenance routines do get run.

Background: I am in the process of getting ready to roll out a whole lotta laptops and am looking into solutions to problems I didn’t know I had. In the process of all of this – I did find a few Desktops that via their ‘good fortune’ they had managed to miss the daily, weekly, monthly cron jobs for almost 2 years…. amazing what well timed power shutdowns will do <sigh>

Yes, installing anacron is a solution but it too has issues that can "break" a happy Mac baseline install setup. As in Who’s Anacron do you install? via Fink? roll your own? Will the "next" OS upgrade/update break a library or patch "something" that will require tweaking "something" or rebuilding "something" to make anacron stay happy and keep running? In my mind it is a "non-standard" solution and may require additional maintenance over time. I am looking for a solution that uses the built-in ‘kit’ as much as possible.

Enter XJanitor – a perl script that turns absolute time into relative time.

http://theapotek.com/teknotes/archives/000040.html

My only mods to the script itself were to annotate with some whitespace for readability.

I’ll upload to the file area (look in Article support)
https://www.afp548.com/filemgmt_data/files/XJanitor-03-21.zip

How to use it – I’ll differ from the author’s how-to slightly.

Firstly copy the script to /Library/Scripts

sudo cp source/XJanitor.pl /Library/Scripts/XJanitor.pl

let’s lock it down as the author suggests
sudo chmod 700 /Library/Scripts/XJanitor.pl
sudo chown root:admin /Library/Scripts/XJanitor.pl

now to modify crontab to reflect that we want to use XJanitor instead of periodic
…. change /etc/crontab to look something like this

note

since I am working with Laptops at the moment – and I don’t want the script to run while on battery – I have cron check at the top of every hour the status of XJanitor

sudo pico /etc/crontab

do daily/weekly/monthly maintenance via XJanitor

00 * * * * root @AppleNotOnBattery /Library/Scripts/XJanitor.pl

Run daily/weekly/monthly jobs.

15 3 * * * root periodic daily

30 4 * * 6 root periodic weekly

#30 5 1 * * root periodic monthly

the way the script is designed, when first run, it will run all three jobs, daily, weekly, monthly and then based on the time stamp of the output files of those "outfiles" it will wait to run again at the first opportunity.

So if it runs the first time at noon, and the computer is shutdown, and then turned back on at 2:30 the following day, at the top of the hour cron fires off the scripts daily gets run. The file stamp get reset to 3PM for the following day – and so on… its all relative to the runtime.

Another thing that can be done with XJanitor:

it can be used to email you its ‘status’ – a phone home feature

Line 57 or so in XJanitor.pl

——————-

ADVANCED OPTIONS –

——————-

my($admin) = "";

add a local email address such as laptop.alert so the line reads

my($admin) = "laptop.alert";
save and exit

now go into /etc/aliases
sudo pico /etc/aliases

find a nice blank line in the

put your local aliases here section

and add

laptop.alert: youremail@realserver.com

make it a real email addy that can receive email from a laptop that may or may not be a valid "sender" (as in my-laptop.local or somesuch)

save and exit

then
rebuild the alias index
sudo newaliases
and
sudo postfix reload
or sudo postfix start

If postfix is not configured to send mail directly revisit other articles here at AFP548 or over at macosxhints.

once this is done, the daily, weekly, monthly runs will email the output of the jobs to the "laptop.alert" email account. "laptop phone home".

Thoughts?

Exit mobile version