Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Editing files in a Remote Linux machine using Java

 
Dorothy Taylor
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Bartender
    Posts: 1166
    17
    Java Linux Netbeans IDE
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 104
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ok, I want to do it programmatically not manually. So opening a file and editing it is not an option
     
    Richard Tookey
    Bartender
    Posts: 1166
    17
    Java Linux Netbeans IDE
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 24208
    35
    Chrome Eclipse IDE Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    A third option is to run the batch-mode editing command on machine B using ssh; for example, something like

     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic