-KaaL-
08-31-2009, 04:30 PM
I want to write this code in a php file.. that executes a shell command...
if(!($stream = ssh2_exec($con, "(echo "g/${123.123.123.123}/d"; echo 'wq') | ex -s /sources/sample.txt" )) ){
echo "fail: unable to execute command\n";
i tried using the below command
if(!($stream = ssh2_exec($con, "(echo \"g/${123.123.123.123}/d\"; echo 'wq') | ex -s /sources/sample.txt" )) ){
echo "fail: unable to execute command\n";
but i get error with this saying..
Parse error: syntax error, unexpected T_DNUMBER in /path/to/this/file.php on line 64 // line 64 is nothing but the code written above
Thank you
mattle
08-31-2009, 06:07 PM
My guess would be that php is trying to interpret the $ in the regex as a variable. I'd escape that, or more to the point of your post title, don't mix your quotation marks in the command...use double quotes inside of the command and wrap the whole thing in single quotes. That will take care of escaping...
if(!($stream = ssh2_exec($con, '(echo "g/${123.123.123.123}/d"; echo "wq") | ex -s /sources/sample.txt' )) ){
echo "fail: unable to execute command\n";
godza
08-31-2009, 06:21 PM
Maybe you forget to close starting tag { with } take look below. And the I think you are missing one ) too. And "( should be (" after that $con
<?
if(!($stream = ssh2_exec($con, ("echo \"g/${123.123.123.123}/d\"; echo 'wq') | ex -s /sources/sample.txt" )))){
echo "fail: unable to execute command\n";
} // closing tag missed.
?>
mattle
08-31-2009, 06:37 PM
Maybe you forget to close starting tag { with } take look below. And the I think you are missing one ) too. And "( should be (" after that $con
$ echo "g/${123.123.123.123}/d"; echo 'wq')
bash: syntax error near unexpected token `)'
Doubt it. Pretty sure he meant:
$ (echo "g/\${123.123.123.123}/d"; echo 'wq')
g/${123.123.123.123}/d
wq
Which brings me to a correction in my post...you will still need to escape the '$' for the shell, but again, '...\$...' is much nicer than "...\\\$..."
As to the closing brace, of course, it is needed, but it's unrelated to the original question. Probably just a case of overly-cropped code :)
godza
08-31-2009, 06:37 PM
Maybe better example would be:
<?
$con = ssh2_connect('codename.fi', 22);
$blaah='echo \"g/\${123.123.123.123}/d\"; echo \"wq\") | ex -s /sources/sample.txt\"';
if(!($stream = ssh2_exec($con, ($blaah)))){
echo "fail: unable to execute command\n";
} // closing tag missed.
?>
-KaaL-
08-31-2009, 09:48 PM
thnx for the replies
if(!($stream = ssh2_exec($con, "(echo \"g/$123.123.123.123/d\"; echo 'wq') | ex -s /sources/sample.txt" )) ){
echo "fail: unable to execute command\n";
that also did the trick
Hanratty
09-04-2009, 10:05 AM
I tried / backslashing to escape but didn't work right now i'm making seperate values for each part of my date, and concacting them it would be easier for me to use the date function like: date(m/d/y:h) ...etc.... but i would need to know how to properly escape those characters
here's my code:
$month = date(m);
$day = date(d);
$year = date(Y);
$hour = date(h);
$minute = date(i);
echo $day.'/'.$month.'/'.$year.':'.$hour.':'.$minute;
mattle
09-04-2009, 05:24 PM
Maybe I'm missing something here, but what's wrong with:
echo date("d/m/Y:h:m");