“ On Mac OS X I couldn't get my FileMaker 11 Server-side script to run or ScriptMaster to write a file as a server side plug-in. The server schedule showed “Aborted by user†messages, despite permissions set to fmserver/fmsadmin. Also, ScriptMaster's WriteToFile only showed 'ERROR.' Using the client plug-in worked, but I needed everything to run on the server. So, I turned to the Terminal to set up a cron (a scheduled task on the Mac).
This entailed making the dates in the “autoReport.sh†script dynamic, to retrieve data for the previous day’s date. Matt’s process handled this in the FileMaker script that wrote each line into the “autoReport.sh†document generated by the WriteToFile function. Instead, I had to rely on this inside the file using bash and had to convert each line, where the date would become a variable with yesterday’s date. Getting today's date was no problem. Getting yesterday's date also was simple. Setting them as variables proved a little rougher. Eventually I combined two examples and ended up with a pair of lines to create the variable.
let YESTERDAY=`date '+%s'`-86400
YDATE=`date -r $YESTERDAY '+%Y-%m-%d'`
I then could use $YDATE in place of the start and end date parameters. Before and after:
php Report.php GOOGLE_ID 2011-03-16 2011-03-16 Absolute_Unique_Visitors
php Report.php GOOGLE_ID $YDATE $YDATE Absolute_Unique_Visitors
I updated the script for each of the reports and ran “autoReport.sh†manually in the Terminal, creating my records in FileMaker. To automate the process I created a cron with the command “crontab –e†and edited the cron with the Terminal editor called nano. The crontab line consists of time and day selections separated by tabs, much like a FileMaker Server schedule, then the command and path to the script.
30 1 * * * sh /Library/FileMaker\ Server/Data/Scripts/autoReport.sh
The sequence: minute, hour, day of month, month, day of week, command & path. This action would run every day of the week at 1:30AM.
My first attempts failed with the message that it could not open “Report.php.†Crontab seems to prefer absolute paths, so I changed the path inside “autoReport.sh†and also added a –f to access the file. I also changed the path inside “Report.php†from relative to absolute.
php -f /Library/FileMaker\ Server/Data/Scripts/Report.php GOOGLE_ID $YDATE $YDATE Absolute_Unique_Visitors
$filename = '/Library/FileMaker Server/Data/Scripts/Reports/'.$reportType.'.php';
This time the cron job ran without a hitch, and I could see the data populating into FileMaker. I now had an automated method on the Mac to pull in my Google Analytics data into FileMaker using the processed detailed by Matt. I'm not sure why the server script failed on the Mac, and why the plug-in also failed. Thanks again to Matt for his great webinar and the resources that he put together. ”