Thread: Simple bash syntax not honored halfway through macro

Started: 2019-04-10 02:22:52
Last activity: 2019-04-10 13:43:40
Topics: SAC Help
Jacob Gochenour
2019-04-10 02:22:52
I wrote a macro in which loops through sac files in a directory and partitions them into smaller files depending on the amount of data points in the file. The macro then moves the original fine into a backup directory. This works great for directories containing only a few sac files; however, if there are many sac files in the directory, sac quits honoring the bash mv command and terminates the script with an error saying mv is not a valid sac command. Once this happens, commands such as cd and ls can’t even be used unless sac is quit then reopened. Does anyone have any idea how to mitigate this issue?

Sent from my iPhone

  • George Helffrich
    2019-04-10 13:43:40
    Dear All -

    I suspect that you are using the “DO <var> WILD <pattern>” command for your looping. If a lot of files match the pattern, it can overflow an internal buffer in SAC, leading to the unpredictable behavior that you report. (SAC should be better at checking for that case and simply reporting a problem rather than failing in this obscure way; sorry for that.)

    A better approach is to make a macro that processes ONE file (checks its size, resizes it if necessary, and moves it) and then make a list of all files that need to be processed that way. For example, suppose your macro to process the file is called “resize” which takes as a parameter one file name to check. In the shell, build up a list of files to check like this:

    # ls <pattern> | awk ‘{print “m resize”,$1}’ > /tmp/sac.in

    The pattern is the same in your original macro's "DO … WILD <pattern>”. That command builds a list of files the need to be examined. Then run sac:

    # sac
    SAC> m /tmp/sac.in
    SAC> message “Finished processing!”

    This effectively unrolls the loop in your SAC macro and makes it into a list of individual SAC macro calls.

    Why is this approach better? Well, you can debug the “resize” macro on one file at a time. When you’re sure it works in all cases then you can unleash it on all the files you need to process.

    On 10 Apr 2019, at 03:34, Jacob Gochenour <jacobgochenour<at>icloud.com> wrote:

    I wrote a macro in which loops through sac files in a directory and partitions them into smaller files depending on the amount of data points in the file. The macro then moves the original fine into a backup directory. This works great for directories containing only a few sac files; however, if there are many sac files in the directory, sac quits honoring the bash mv command and terminates the script with an error saying mv is not a valid sac command. Once this happens, commands such as cd and ls can’t even be used unless sac is quit then reopened. Does anyone have any idea how to mitigate this issue?

    Sent from my iPhone

    ----------------------
    SAC Help
    Topic home: http://ds.iris.edu/message-center/topic/sac-help/ | Unsubscribe: sac-help-unsubscribe<at>lists.ds.iris.edu

    Sent from the IRIS Message Center (http://ds.iris.edu/message-center/)
    Update subscription preferences at http://ds.iris.edu/account/profile/



    George Helffrich
    george<at>elsi.jp


23:37:55 v.22510d55