Solved

CentOS/SSH:  append text to file

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux Mint 18 31 79
Oracle 12c patching 1 64
bash while loop reading input from data section in script 7 65
Codiing Non-Existent Links 4 68
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

863 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

19 Experts available now in Live!

Get 1:1 Help Now