The usual unix/linux approach is locking based on a PID file with the refinements described in the thread referenced by andreas1234567. These refinements generally deal with issues of scripts that hang or terminate prematurely. The situation you describe seems to have greater potential for creating a race condition because there are multiple scripts in the picture rather than a single script with multiple potential instances.

One approach would be to create a script that transfers files to the ftp server when they appear in a watched directory. This script could be run as a daemon or through cron depending on how quickly you need it to act. This script would need to assure that only one instance was active at a time, but the techniques described in the aforementioned node should work well for this purpose. Your existing scripts would need to be modified to move files to the watched directory rather than sending them to the remote server.

On linux, another approach would be to use the fuse (filesystem in userspace) kernel module with curlftpfs (LftpFS may be a reasonable alternative; avoid FuseFTP as it is not very robust) to mount the remote server as a local file system (I believe this can be done through fstab). This also lets a single entity manage the connection to the remote ftp server. The existing scripts would need to be modified to write files to the appropriate local path (functionally sending them to the remote server via ftp). I believe that this approach will allow the ftp connection to timeout while not in use and will only reconnect when needed; it would be best to verify that this is correct.


In reply to Re: Synchronisation between multiple scripts by eye
in thread Synchronisation between multiple scripts by weismat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.