Solved

CentOS/SSH:  append text to file

Posted on 2011-03-16
5
863 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
When it comes to security, there are always trade-offs between security and convenience/ease of administration. This article examines some of the main pros and cons of using key authentication vs password authentication for hosting an SFTP server.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now