Solved

CentOS/SSH:  append text to file

Posted on 2011-03-16
5
872 Views
Last Modified: 2012-05-11
Hi All,

How do i add text to the bottom of a file using SSH?


Thanks
0
Comment
Question by:detox1978
  • 3
  • 2
5 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35149163
ssh is a secure remote shell and not a text manipulation program.

What exactly is your requirement?

wmp
0
 
LVL 2

Author Comment

by:detox1978
ID: 35149206
I want PHP to manage email forwarding.

Currently I connect via SSH and append a line of text to /etc/postfix/virtual using vi

Ideally i'd like to do this via a script online.

0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 35149244
ssh user@host 'echo "my new line of text" >> /etc/postfix/virtual'

wmp
0
 
LVL 2

Author Comment

by:detox1978
ID: 35149433
That worked thanks.

When i check the file it has blue "^M" at the end of each line, is this important?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35149511
This is because you obviously transferred the file from Windows to Linux in FTP ASCII mode.
It can cause problems, depending on the application.
I assume Postfix is able to handle it correctly, but better use "BINARY" transfer in the future.
The ^M (carriage return) characters are not related to the method of appending text with "echo" and ">>", however.

wmp
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question