0

I'm quite new using ssh command thru a php script.

Here my script :

<?
$ark =123456-78

$Sark= substr("$ark", 0, -3); //123456
$stream = ssh2_exec($connection, 'grep $sark /var/log/transfer.log');
...
?>

When I put the value of $sark in clear, the ssh execution work fine but when I use the variable it's not working ( very long loading).

I also tried to declare my variable as

$sark= escapeshellarg('$sark');

I know that a php variable cannot be recognized in ssh command. I have not yet found any solution. Do you have any idea to solve this issue ?

Thank you Rflow

1
  • 1
    When using substitution for $sark - you should be using double quotes not single round the whole string (also try and ensure use same case for consistency). Commented Jul 21, 2017 at 16:15

1 Answer 1

1
  1. You need to escape it in your command
  2. You where missing ;
  3. It's $Sark not $sark

Result:

<?php
$ark =123456-78;

$Sark= substr("$ark", 0, -3); //123456
$stream = ssh2_exec($connection, 'grep '.$Sark.' /var/log/transfer.log');
...
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you , you made my day ;) It works just fine :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.