vendredi 10 septembre 2021

How to catch SSH command output contain sub string ? - Laravel 5.8

I'm trying to catch the output of the command and throw error/success accordingly.

$resultFromServer = []; 
SSH::run($command, function($line)
{
    echo $line.PHP_EOL;

    if($line!= null) {
        array_push($resultFromServer, $line); // crash 
    }
});

dd($resultFromServer);

Check out my output

WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/config WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/config Error: open test.yaml: no such file or directory

[]

I'm trying to look for this string Error: and whatever to the right of it, I will display in my alert message.

Error: open test.yaml: no such file or directory

I'm trying

to store each line into an array and loop through and check for string contain, but I can't even store it into the array.

I kept getting a crash - if - I uncomment that line

enter image description here

How do I prevent the crash ? Do I need to add some sleep() ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire