in reply to Writing to a file on two different servers

There is no direct way to open a filehandle on a remote server; you would need to open a socket to the remote server, with a process at the other end of the socket cooperating in writing the file. (For example, HTTP works by having your browser open a socket to the remote machine and sending a request; then the web server on the remote machine cooperates by sending back the requested data.)

The easiest solution in this case is probably to create the configuration file locally, and then upload it to the remote server with Net::FTP.

  • Comment on Re: Writing to a file on two different servers

Replies are listed 'Best First'.
Re: Re: Writing to a file on two different servers
by belize (Deacon) on Dec 06, 2000 at 04:07 UTC
    OK, alternatively, could I read a config file from a remote server? The reason I ask is that I have program that will run on two different servers, but will use the exact same flat file for data. Instead of having to update the flat file twice, it would be best to update it once and then have both servers read the single flat file.
      You'll still need some cooperation from the remote server to get the file. You could FTP it, scp it, put it on the web and get it with LWP... There are lots of different ways.

      I think what you need to consider first is when is the best time for the configuration file to be transfered; when it changes, or when the scripts run. It may make more sense to distribute the configuration file when it changes, and have the scripts just run on a local copy, so that the script doesn't have to open a remote connection everytime it runs. On the other hand, you might want to avoid changing the file on one server and forgetting to upload it to the other server.

      That decision will, of course, influence how this system is implemented.

      If the files are supposed to be exactly the same, why not creat the file on your current server and then use FTP to copy it to the other one?

      --
      <http://www.dave.org.uk>

      "Perl makes the fun jobs fun
      and the boring jobs bearable" - me