Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've already setup SSH usage in PHP and most of the things work.

Now what I want to do is that I'm looking to edit a line in a file and replace it back. It works directly on the server but can't seem to get it working with PHP files. Here is what I'm trying.

$new_line1 = 'Line $I want to add - The $I has to go into the file as it is';
$new_line2 = 'Ending $text of the line - $text again goes into file;
$query = "Addition to line";
$exec1= 'cd /root; perl -pe "s/.*/' ;
$exec2=  '/ if $. == 37" Edit.sh > Edited.sh';
$new="$exec1$new_line1$query$new_line2$exec2";
$edit="cd /root/mp; cp Edited.sh Edit.sh";
echo $ssh->exec($new);
echo $ssh->exec($edit);

Now the thing is that running the perl command directly in SSH works without any errors but when I run this through PHP I get the error: Substitution replacement not terminated at -e line 1. I want to know why would it work this way and not that?

share|improve this question

closed as off topic by Tom O'Connor, EEAA, Lucas Kauffman, Magellan, mdpc Dec 16 '12 at 5:36

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
You might want to review your previously asked questions, and accept some damn answers. You have a 0% accept rate, which indicates to us that we're unlikely to get the accepted answer reputation points by answering a question for you, as a result, we're unlikely to answer any further questions. –  Tom O'Connor Jul 9 '12 at 10:01
    
I've thanked people before in my questions whenever their knowledge has helped me. EDIT : Oh well I'm sorry - I didn't notice their was an accept button as well. I'll do that –  Asad Moeen Jul 9 '12 at 13:44
3  
83% accept rate! That's better.. Doesn't it feel good to help the community flourish? –  Tom O'Connor Jul 9 '12 at 14:17

1 Answer 1

up vote 3 down vote accepted

Oh this looks like a security and reliability disaster waiting to happen.

Short answer: there is an opening quote in $exec1 but I can't find the matching closing quote.

More generally, if anyone manages to sneak a quote into line1 or line2, this is going to go wrong. This basically provides a web interface for anyone with access to it to run arbitary code on your computer ...

share|improve this answer
    
The matching code I actually put into $exec2. This was actually a single line command but I had to split it up because some $cmds had to go exactly and some needed values parsed. –  Asad Moeen Jul 9 '12 at 9:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.