9 Replies Latest reply on May 5, 2014 5:57 AM by Vincent_L

    Server Script to import FM Server Logs

    mr_scott

      Hello:

       

      I'm trying to create a server-side script that will import Event and Stat logs into a temporary table, sort them by the timestamp value in ascending order, then import the sorted records into another file to update and append the existing records.

       

      I've created a server script schedule for the Master script, but it keeps encountering an error 3 (command unavilable). I created another script schedule on the temporary file to run just the vents import, and it keeps encountering an error 100 (missing file). When creating the scripts, I set the compatbility popup menu for Server, and don't see that I included any steps that aren't server compatible, but maybe someone can point me to my errors.

       

      Here is the basic import script for the Events.log import, which sets a path into a local variable (file type popup menu is set to "All Available"):

      Set Variable [$eventsFilePath; Value:"file:/Library/FileMaker Server/Logs/Event.log"]

      Import Records [No dialog; "$eventsFilePath"; Add; Mac Roman]

       

      I also tried setting the path to be "filemac:/Macintosh HD/Library/FileMaker Server/Logs/Event.log", but that didn't work either.

       

      FYI: I currently have 4 plug-ins installed on the server: bBox, jsBox, ScriptMaster, and Base Elements. Is it possible this is unsupported without a plugin?

       

      Thanks in advance,

      - - Scott

        • 1. Re: Server Script to import FM Server Logs
          wimdecorte

          mr_scott wrote:

           

          Hello:

           

           

          Set Variable [$eventsFilePath; Value:"file:/Library/FileMaker Server/Logs/Event.log"]

          Import Records [No dialog; "$eventsFilePath"; Add; Mac Roman]

           

           

          FMS can only import from what is in its Documents folder (or the temporary path).

          So you have to use a Server Script Sequence Schedule instead of a regular Script Schedule.  Your sequence would use a shell script to copy the logs into the Docs folder, followed by your import script.

          • 2. Re: Server Script to import FM Server Logs
            mr_scott

            Thanks, Wim.

             

            Now, I just have to figure out how to get that shell script to work from within the Sequence, as it throws "invalid account name or password" or "aborted; aborted by user" errors. I can run the shell script through the terminal, so now I'm working our the other problem: importing with PSoS between two hosted files.

             

            Best regards,

            - - Scott

            • 3. Re: Server Script to import FM Server Logs
              wimdecorte

              Unless you've specified a user account, it will run as fmserver, so keep that in mind for whatever it needs to do.  Just copying files should not be a problem.

               

              Also, keep in mind that you should exit the shell script with an explicit exit status.  A non-zero status will signal a failure and will prevent the FM script in the sequence from running.

              • 4. Re: Server Script to import FM Server Logs
                mr_scott

                Hi, Wim:

                 

                Here's the basic code I saved as "01_copy_recursive.sh":

                     cp -R -p /Library/FileMaker\ Server/Logs /Library/FileMaker\ Server/Data/Documents/UploadTemp_FMSlogs

                 

                     exit

                 

                I've pasted those lines into the Terminal and it works every time I hit the return key.

                 

                So, I created a Shell script schedule in FMS 13 admin console to run once, just so I could see if it works there, before chaining it with my FM master script in a sequence. I did not specify a user account, but it throws the error "aboted by user" and does not work. If I change it user use the local user account on the computer hosting FMS, it throws the invalid user/password error.

                 

                I'm researching the OS X developer library to see what I can learn about Shell scripting.

                 

                Thanks,

                - - Scott

                • 5. Re: Server Script to import FM Server Logs
                  Vincent_L

                  It may help, but of course you'll have to embed this in an applescript due to the password (and then run the Applescript in command line)

                   

                  http://fmforums.com/forum/topic/81512-basic-bash-script/

                   

                  To act as fmuser without knowing the pw:

                   

                  - in a Terminal:

                   

                  # going to root
                  su

                   

                  # after entering pw

                   

                  sudo -u fmserver /Library/FileMaker\ Server/Data/Scripts/touch.sh

                   


                  That should execute the script as fmserver.

                  • 6. Re: Server Script to import FM Server Logs
                    wimdecorte

                    I would suggest setting up what is called a "service account" so you can assign it the proper privileges needed for just the task and use that one explicitly in the schedule.

                    • 7. Re: Server Script to import FM Server Logs
                      mr_scott

                      Hi, Vincent:

                       

                      I will look into your suggestion and the link on fmForums. Oh…I've been reading with keen interest the good questions you've been posting to the Performance Panel!

                       

                      Best regards,

                      - - Scott

                      • 8. Re: Server Script to import FM Server Logs
                        mr_scott

                        Hi, Wim:

                         

                        You're up early today! I had just such an account on my previous server (FMS12), so I will do he same here. Except for the Shell command in the script sequence, I was able to get all of the other things to work in importing from the log files, pasring, sorting, limiting the records based on Scriptparameter passed from client through PSoS, deleting records older than what is already in Target file, then importing sorted data from the xported .tab file.

                         

                        I'll look at the AppleScript approach mentoned by Vincent_L for getting the Shell to run.

                         

                        Thanks,

                        - - Scott

                        • 9. Re: Server Script to import FM Server Logs
                          Vincent_L

                          Also, you may consider, rather than server side commands, to use Goya BaseElement Plug-In 's BE_ExecuteSystemCommand*. I'm in the process of transitionning all my applescripts and command to it, with great result.

                          It works server side, and is able to run any command. Maybe you comand wil work as it is today, cause maybe it would run it as fmserver user.

                           

                           

                          * Be aware that it uses Bash as ashele ≠ from terminal, mostly ok by some problems arise with tabs, \t. And use absolute path, as the default folder is /. You'll find more in support forum of BaseElements