Solved

CentOS/SSH:  append text to file

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
We all know how boring and exhausting it is to transfer huge web projects developed locally to a webserver simply via FTP. The File Transfer Protocol is a really nice solution if you need to transfer small amounts of files, but if you're plannin…
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…
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.:

809 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