Running radmind via cron (by way of periodic) and on-demand


Here are some more of the scripts I use to automate radmind...

Rather than editing crontab files, I put a script in /private/etc/periodic/daily, called 900.autoradmind:
900.autoradmind


This script checks to see the last time radmind ran; sees if there are any needed updates on the server (via ktcheck), and checks to see if anyone is logged in at the console.
If no-one is logged in, it runs a radmind session via a script at /usr/local/radmind/scripts/radmindNow
If someone is logged in and there are updates on the server, or it has been more than seven days since the last radmind session, it attempts to log the user out gracefully. If there are any unsaved documents, this will fail.
If it fails to run radmind and it's been more than seven days since the last run, it notifies the admin and alerts the user. I'll share this alert app at a later date (once I've made it easily customizable...)

When the 900.autoradmind script does run radmind, it calls this script:
radmindNow


#!/bin/sh

radmindTriggerFile="/var/radmind/client/.radmindOnLogout"
restartCheckFile="/usr/local/radmind/tmp/restartCheck.T"

touch $radmindTriggerFile
/usr/local/radmind/scripts/logoutHook

exit 0

Which as you can see, simply calls the logoutHook:
logoutHook


#!/bin/sh

radmindTriggerFile="/var/radmind/client/.radmindOnLogout"
restartCheckFile="/usr/local/radmind/tmp/restartCheck.T"

if [ -f $radmindTriggerFile ]; then
   rm $radmindTriggerFile
   rm -f $restartCheckFile
   /Applications/Utilities/radmind/iHook.app/Contents/MacOS/iHook --no-titlebar --script=/usr/local/radmind/scripts/run_radmind.pl
   if [ -s $restartCheckFile ]; then
      shutdown -r now
   fi
fi
exit 0


Which in turn calls iHook and my run_radmind script, which is detailed elsewhere.

This arrangement gives me a lot of flexibility. I can ssh in and run the run_radmind script if I want to see the output, but it's not important (or desirable) for the user at the machine to see the output. (Typically I'll do this if I know no-one is logged in and no-one is likely to log in.) Or, if I want iHook to come up and give the user some indication of what is going on, I can run the "radmindNow" script. Finally, since I am using a logoutHook script, I can let the user trigger a radmind session by running this app:
Update this Mac.zip




Which is just an AppleScript applet:
activate
set theMessage to "Warning: update this machine?" & return & return & "You will be logged out and software on this machine will be updated. This may take several minutes and may require a restart. Are you sure you want to continue?"
display dialog theMessage buttons {"No", "Yes"} default button "Yes" giving up after 15 with icon caution
if (button returned of result is equal to "Yes") then
       try
              do shell script "touch /var/radmind/client/.radmindOnLogout"
              ignoring application responses
                     tell application "loginwindow" to «event aevtrlgo»
              end ignoring
       on error theError
              display dialog "Error: " & theError giving up after 60
       end try
end if


If the user launches this application and clicks yes, they will be logged out and a radmind session will run.

Posted: Mon - May 10, 2004 at 10:10 PM      


©