2

I'm writing a new backup script in PowerShell to back up our Azure SQL.

After the backup, I need to write into a logfile on a remote Linux server.

I thought about using plink (the PuTTY command line tool). More or less like this:

plink user@server /var/log/logfile<"TEXT"

However, most of you will remark that this isn't possible, and I also learned this :)

Is there no easy way to add a line of text to an existing file on a remote Linux system using plink?

platzhersh
  • 123
  • 6

1 Answers1

1

One pretty common method is to use tee.  Try one of these.

echo "TEXT"        | plink.exe user@server tee /var/log/logfile

type localfile.txt | plink.exe user@server tee /var/log/logfile

To append the data to the end of the file then use tee -a:

echo "TEXT"        | plink.exe user@server tee -a /var/log/logfile
 
type localfile.txt | plink.exe user@server tee -a /var/log/logfile
Zoredache
  • 19,828
  • 8
  • 50
  • 72
  • 1
    Thx! Actually I should have known this command but I've never used it before. I did only one small change to make it append the text and not overwrite it everytime: echo "TEXT" | plink.exe user@server tee -a /var/log/logfile – platzhersh Mar 06 '12 at 07:19