aspose file tools*
The moose likes Linux / UNIX and the fly likes Editing files in a Remote Linux machine using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Editing files in a Remote Linux machine using Java" Watch "Editing files in a Remote Linux machine using Java" New topic
Author

Editing files in a Remote Linux machine using Java

Dorothy Taylor
Ranch Hand

Joined: Nov 26, 2007
Posts: 104
I am writing a Java code for Linux RHEL 5 machine. The requirement is that while sitting at machine A, I should be able to edit some files in a remote machine B. Both machine A & B are RHEL. Now the following possibilities are there. Can anyone please suggest which is better or if any other way is there:

  • Write a shell script to do this. Execute the shell script from A such that changes happen in B

    Write a java code on A, that is able to login to B and edit files in B.

    Write a java file editing utility (pattern-matching thing). Push this util on B through another java code. Execute the file edit util in B. Somehow the trigger for executing the util in B should also be given by
  • Richard Tookey
    Ranch Hand

    Joined: Aug 27, 2012
    Posts: 1111
        
      10

    I must be missing something because this seems trivial. It can be done in at least two ways. For example

    1) SSH from A to B and then use your favourite editor to edit the files directly on B. If your editor needs X then just enable it by supplying the -X argument to 'ssh' .

    2) Using NFS mount the B directory where the Java files are located on a directly on A. You can then edit the files as if they were actually on A.
    Dorothy Taylor
    Ranch Hand

    Joined: Nov 26, 2007
    Posts: 104
    Ok, I want to do it programmatically not manually. So opening a file and editing it is not an option
    Richard Tookey
    Ranch Hand

    Joined: Aug 27, 2012
    Posts: 1111
        
      10

    Dorothy Taylor wrote:Ok, I want to do it programmatically not manually. So opening a file and editing it is not an option


    OK - my misunderstanding . You could use one of the Java (or whatever language you are writing in) SFTP libraries to read the remote file from machine B into your program running on A, edit it and then write it back again. This would require you to have an SFTP server running on machine B. If you have installed openssh on machine B then you automatically get an SFTP server.

    My second option is still applicable - using NFS just mount the B directory on A and your program can access it directly.
    Ernest Friedman-Hill
    author and iconoclast
    Marshal

    Joined: Jul 08, 2003
    Posts: 24187
        
      34

    A third option is to run the batch-mode editing command on machine B using ssh; for example, something like



    [Jess in Action][AskingGoodQuestions]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Editing files in a Remote Linux machine using Java