Sometimes the best way to perform complex behavior in a callback is to put that behavior into an external script which can take the job ID or the job ID and agenda item name (the frame number) as arguments.
The following is an example of a callback that runs for every frame when the job completes. Admittedly, it may be more efficient to run it once and have the external script iterate over every frame, but this is for demonstration purposes.
In line 41 of the above script, using "python" assumes that python is in the supervisor user's PATH environment. If not, use the full path to python. If the python script can be invoked on its own (without calling it as an argument to the python executable itself), then you can leave out "python" all together.
Remember, callbacks are executed on the supervisor by the user who is running the supervisor (typically the local system account or "root"). Keep this in mind when reading from or writing to the shared file system.