mardi 5 février 2019

Why if (condition) don't work with '{""}''

I'm setting up a PHP code that takes some infos from Bash and put them in PHP. My If statement don't sort what i write or get from bash.

This is for a Server Apache2 on Linux. I've tried to put my string that i want to use in my condition in a variable.

GameToken = `grep "Matching server game" "${FactorioServerLogPath}" 2> /dev/null | awk '{print $7}' | tail -1 | tail -c +2 | head -c -2`;

$GameState = `curl -s -X GET -H "Content-type: application/json" -H "Accept: application/json" "https://multiplayer.factorio.com/get-game-details/$GameToken"`;

if ( $GameState != '{"message":"no game for given game_id"}' ) {
  echo "<h2> The Server is up and running </h2>";
} else {
  echo "<h2> The Server is currently turned off </h2>";
}

The outpout should look like The Server is currently turned off when the variable $GameState is not like {"message":"no game for given game_id"}.

Aucun commentaire:

Enregistrer un commentaire