• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Editing files in a Remote Linux machine using Java

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  •  
    Bartender
    Posts: 1166
    17
    Netbeans IDE Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Netbeans IDE Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    author and iconoclast
    Posts: 24207
    46
    Mac OS X Eclipse IDE Chrome
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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

     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic