edit remote files
Anonymous Monk
created: 2006-09-04 03:08:14
Hello All: Need a quick solution. How can I edit couple of single lines of code in a remote script with perl? Please suggest. thanks
Re: edit remote files
created: 2006-09-04 03:20:03

Quick solutions will be more forthcoming for questions composed to include the details vital to our coming up with a solution.

Where is the remote script? What method do you intend to use to access it? There's simply not enough detail in your question to make it answerable.


Dave

Re^2: edit remote files
created: 2006-09-04 03:40:41
Hello Dave: Thanks for getting back. Well apologies for not being detail as well. Well here's the scenario. I have my perl script running on a machine say IP1. I need to change the contents of a configuration file on an other/remote machine say IP2. Contents being one line which is actually a variable called tmp.id = 0. I have to modify the value of 0 to a different integer based on the value supplied in the input file that am going to read with my perl script. Now am not aware how can i change the value of '0' to the one i read from the input file of the config file which is on a different machine?? Please suggest. also lemme know if you need more information. thanks
Re^3: edit remote files
created: 2006-09-04 03:47:08
Hi Ananymous Monk,

Inside your script,connect the remote machine by using Net::Telnet module and change the contents of the config file.
It is a brief.Try yourself and post the code if you are facing anymore problem,so that we can helpout you more.

Thanks.
Re^3: edit remote files
created: 2006-09-04 03:56:24
If you are feeling particularly brave....
ssh user@IP2 'perl -pi".bak" -e "s/tmp\.id = 0/tmp\.id = 1/" your_config_file'
That would do an in-place edit, and create a backup of your original file called "your_config_file.bak".
See [doc://perlrun|perldoc perlrun] (the -i switch).

Update: I missed that you said that you wanted to do this from within an existing script. In that case, you'll probably be wanting to use [mod://Net:SSH]

Re^2: edit remote files
created: 2006-09-04 05:11:31
You can also use RPCs like SOAP::Lite for executing a remote subfunction and write the file modification script in that subfunction.
Re: edit remote files
created: 2006-09-04 11:47:12
or just create/edit the file locally on the same machine as your perl script, and ftp over using Net::FTP
Re: edit remote files
created: 2006-09-04 14:28:21
The number of replies going in different directions seems to indicate that you should take a look at How (Not) To Ask A Question and How do I post a question effectively?.

There are any number of answers to your question, depending upon the requirements that you have and what you are already doing in your script. You could create the file locally, and copy it to the remote machine using ftp, sftp, or scp. You could open a port just for this, accepting the remote file via this port, and then feed the new file contents back over the port to the connecting/authenticating machine. You could copy the remote file to a local temp file, and run some checks/edits of it's contents and then copy it back, or any of the other suggestions that you have received.

Personally, I tend to favor using an existing protocol, such as scp or rsync plus ssh. Whether you just copy a standard file to the remote machine mostly depends upon whether these files are going to have/need local changes made to them.

perlmonks.org content © perlmonks.org and Anonymous Monk, davido, johnnywang, madtoperl, McDarren, nishanth_ev, RobPayne

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03