System level scripts can be very helpful to use with FileMaker Server. There are two problems I was able to solve by using system level scripts, and now I use these two processes on a daily basis. The first problem I came across was that the server machine was always running out of memory.
To solve this, I created a process that creates a zip file of my backup. It then move the backup to another machine. The second issue I came across was a client needed to refresh FileMaker data from another data source on a nightly basis.
Using ftp to access a machine and then grabbing a file to import it into FileMaker solved this request. I will go into how to do each of these in detail.
Creating Zip Files of the Backup and Moving Them to Another Location
This example assumes you are on a Mac.
- First, set up a schedule that keeps only one backup in the folder. In this example, I call that backup “ScriptedBackups.” For this particular client, I have a development FileMaker file and a production FileMaker file, so I need to create a back up schedule for each one with it’s own separate folder:
- /Volumes/Server HD/Library/FileMaker Server/Data/Backups/ScriptedBackups/Production/
- /Volumes/Server HD/Library/FileMaker Server/Data/Backups/ScriptedBackups/Development/
- Once you have the backup schedule ready, you can create the shell script to zip up the file and then move it to the proper location. Put the scripts in the scripts folder within FileMaker Server (Library/FileMaker Server/Data/Scripts/). The set of scripts available below were written by Jeremiah Small (thank you!). The zip_daily.sh script defines 2 variables: the starting path and the target path. You need to update those 2 paths, and the path to the worker script. The shell script will call the worker script to do all the work; it also adds data to the logger, so you can monitor results. zip_dailysh.sh zip_workersh.sh. A worker script allows you to create as many calling scripts as you wish. You only have to update the two paths. For example, we use a zip_daily.sh, zip_hourly.sh, zip_monthly.sh, and a zip_weekly.sh, and they all call the same worker script.
- Create a new schedule that calls the system level script appropriately. If you call your script zip_daily.sh, create a schedule that calls the script daily.
- Test Now you are done!
- FileMaker server always runs scripts from the root, so file paths need to be absolute, not relative.
- You can also use this same logic to create a schedule that deleted files that are older than x number of days. For example, see purge_183dayssh.txt and purge_workersh.sh (In this calling file, you will need to update all the filepaths).
FTP into Site and Move Files Locally to Import
The example assumes you are on a PC.
- First thing to do is create the scripts to ftp into a server and grab a file. Thank you to Mason Dixon for creating these scripts. He set it up so there is a calling batch script and a corresponding text file with the information. For this example, I want to grab unit_import.csv from the ftp site and move it locally to my documents folder inside of FileMaker server. In the text file, edit the ftp site, user name, password, and destination path as desired. Make sure the path and name of the text file are correct in the batch file. The scripts should be living in “C:Program FilesFileMakerFileMaker ServerDataScripts” and the data files should be living in “C:Program FilesFileMakerFileMaker ServerDataDocuments” doftp_unit_importbat.txt ftpdirectives_unit_import.txt
- Once you have your scripts in place, you want to create a FileMaker Server schedule. The trick here is to use a script sequence schedule, because you don’t want to import the data until the import file has completed its move to the local machine. Create a script sequence to call the batch script you created in step one and then call an import script from FileMaker.
- Test Now you are done!
- This example assumes the import filename and location never changes.
- In the system level scripts, the filename is case sensitive, so be sure it matches the name of the file on the FTP server.
- If the file to be imported doesn’t live in the root of the ftp site, then you can change directory by adding “cd newdirectory” to the text file, before the lcd step.
- If you have issues moving the file from the ftp site, make sure to add ftp.exe as an exception to your firewall.
- You can also use the same logic to export a file from FileMaker, and then move it to an ftp site. For example, see doftp_local_law_exportbat.bat and ftpdirectives_local_law_export.txt.
I hope you find this as useful as I did. I’d be happy to answer any questions via comments or email: email@example.com
Thanks for reading!