A
A
Atraides2018-08-30 12:00:20
PHP
Atraides, 2018-08-30 12:00:20

Pass key value from PHP array to bash script?

Greetings, how best to implement this, there is a php script that accepts a Post request:

<?php

print_r($_REQUEST);
writeToLog($_REQUEST);

function writeToLog($data, $title = '') {
 $log .= (strlen($title) > 0 ? $title : 'DEBUG') . "\n";
 $log .= print_r($data, 1);
 file_put_contents(getcwd() . '/log/hook.log', $log, FILE_APPEND);
 return true;
}

And it simply outputs to the log what came in, and the array comes in this form:
Array
(
    [event] => ONTASKUPDATE
    [data] => Array
        (
            [FIELDS_BEFORE] => Array
                (
                    [ID] => 17267
                )

            [FIELDS_AFTER] => Array
                (
                    [ID] => 17267
                )

            [IS_ACCESSIBLE_BEFORE] => undefined
            [IS_ACCESSIBLE_AFTER] => undefined
        )

    [ts] => 1535618270
    [auth] => Array
        (
            [domain] => xxxxxx
            [client_endpoint] => https://
            [server_endpoint] => https://
            [member_id] => ec5fa65423d3c8f10cf8c2a6b9235318
            [application_token] => 31rfw93yax4enys7zyzjkqfah9qgv98h
        )

)

It is necessary to write the value of the [ID] key - the [FIELDS_BEFORE] field into a certain variable, which can then be passed with the launch of the bash script, so the question actually arose how to display the desired variable [ID]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Drill, 2018-08-30
@Drill

$var=$имя_массива["data"]["FIELDS_BEFORE"]["ID"];
$cmd="/path/to/script.sh $var";
$output=array();
exec($cmd,$output,$return);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question