1

I need a script to set the SERVER variables programatically when executing a PHP script from the CLI.

The idea is to get the SetEnv lines from an apache config file and feed them into the cli execution of the script so that the CRON job can execute with the same environment variables as the web site.

I have the following command

envvars=grep SetEnv $conffile | awk '{print $2"=\""$3"\"";}' | xargs
$envvars php $script

which should execute

arg1="value1" arg2="value2" php somescript.php

But I get the response

arg1=value1: command not found

If I just echo the command I can execute it without a problem.

QUESTION: Why does my bash script not work?

Ablue
  • 1,140
  • 1
  • 12
  • 32
  • If you're trying to pass environment variables, why is your program looking in `$_SERVER`? They don't show up there anyway. – Michael Hampton Dec 03 '18 at 01:08
  • Apache SetEnv directive does. http://php.net/manual/en/reserved.variables.server.php#121008 http://php.net/manual/en/reserved.variables.server.php#97106 – Ablue Dec 03 '18 at 01:26
  • OK, that's Apache-specific then. Environment variables are normally accessed with `getenv()`. You shouldn't rely on that, precisely because it's Apache-specific. – Michael Hampton Dec 03 '18 at 01:34
  • I am accessing them using `getenv()`. The reason I mention SERVER variables is because I the method used by the command line sets SERVER variables. This line of discussion is not really relevant to the question. – Ablue Dec 03 '18 at 01:55
  • You should probably clarify your question, then, so others don't get confused too. – Michael Hampton Dec 03 '18 at 01:59
  • @MichaelHampton there you go. – Ablue Dec 03 '18 at 03:07

0 Answers0