0

I have the following php code

if (!($stream = ssh2_exec($con, 'sed -i \'s/motd=A Minecraft Server/motd=\'.$name.\'s     Server/g\' /home/servers/runner15/server.properties
'))) {

But when I run it instead of replacing the text "motd=A Minecraft Server" to "motd=runner15s Server" it Changes it to motd=..s Server

It's something todo with escaping the quotes

Oh by the way $name holds runner15

Jeremy Sayers
  • 637
  • 4
  • 10
  • 23

2 Answers2

2

Basic PHP strings... ' strings do NOT interpolate variables, so your sed command contains a literal $, n, a, m, e, etc... That'll be interpreted as a non-existent shell varaible on the remote server, and expand to an empty string.

[...snip...]otd=A Minecraft Server/motd=\''.$name.'\'s [..snip...]
                                          ^-------^--- 'exit' the string in your client-side PHP
Marc B
  • 356,200
  • 43
  • 426
  • 500
0

Try escapeshellcmd before ssh2_exec. http://www.php.net/manual/en/function.escapeshellcmd.php

alganet
  • 2,527
  • 13
  • 24