Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

append an expression to a file on remote host

by s_gaurav1091 (Beadle)
on Aug 31, 2005 at 09:57 UTC ( [id://488057]=perlquestion: print w/replies, xml ) Need Help??

s_gaurav1091 has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I have a problem that I want to append an expression to a file on a remote host.I am wriiting a subroutine in a script and i want that subroutine to open a file on a remote host and append an expression.I want to do it through rsh and rcp...is it possible???
  • Comment on append an expression to a file on remote host

Replies are listed 'Best First'.
Re: append an expression to a file on remote host
by redlemon (Hermit) on Aug 31, 2005 at 11:44 UTC
Re: append an expression to a file on remote host
by fauria (Deacon) on Aug 31, 2005 at 10:41 UTC
    I think it could be something like (not tested):
    use Net::SSH::Perl; my $host = 'host'; my $user = 'username'; my $pass = 'password'; my $string = 'Expression to append'; my $cmd = "echo $string >> /path/to/file"; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
Re: append an expression to a file on remote host
by ghenry (Vicar) on Aug 31, 2005 at 10:37 UTC

    What kind of expression?

    Could we see your first attempt?

    Use SSH and SCP instead of RSH/RCP though.

    Walking the road to enlightenment... I found a penguin and a camel on the way.....
    Fancy a yourname@perl.me.uk? Just ask!!!
Re: append an expression to a file on remote host
by blazar (Canon) on Aug 31, 2005 at 14:01 UTC
    Although I have not used them, I remember having noticed in the documentation for Net::SFTP that it provides methods for opening remote files. I wouldn't use rsh and rcp in any case, as far as my opinion is concerned...
Re: append an expression to a file on remote host
by ait (Hermit) on Aug 31, 2005 at 17:58 UTC
    Possible it is indeed.
      Hi, If you have access to the remote machine you can use a simple open method.
      you can go through this code and have some idea....
      Authentication of the remote is also should be there....
      $hostname ="testing";#it may be ip address or remote host name $hostfilename="temp\fooo.ini"; $hostfilename =~ s/\\/\\\\/g; my $file="\\\\$hostname\\$hostfilename"; if(!-f $remotepath){ print "Remote access and add content to remote file\t\Failed"; exit; } else{ #Remote file access open(TEMP,">>$file") or die ("cannot open the remote file '$fi +le':$!"); #Here add your stuff to append data to the remote file close(TEMP); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://488057]
Approved by fauria
Front-paged by fauria
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-25 09:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found