I am writing a bash script designed to run on a remote AMP stack. The script must access the predefined PHP environment variable ($ _ENV).
This is what I want:
db_host=$(php -r 'echo $_ENV{DATABASE_SERVER};')
echo "The DB Host is: $db_host"
This is what I get instead:
db_host1=$(php -r 'echo $_ENV{DATABASE_SERVER};')
echo "The DB Host is: $db_host1"
db_host2=`php -r 'echo get_env(DATABASE_SERVER);'`
echo "The DB Host is: $db_host2"
None of the methods work, both variables return empty. I know that this PHP variable is set, because when I enter it into the terminal (after ssh'ing to the server), I get the expected value:
$ php -r 'echo $_ENV{DATABASE_SERVER};'
# outputs: "internal-db.s173785.gridserver.com"
Technically, the above methods should work, because I managed to get this to work in my script:
php_user=$(php -r 'echo getenv("USER");')
echo php_user is $php_user
Does anyone know what I'm doing wrong? \
*** UPDATE *******
I should mention that I call this script from my local machine as follows:
ssh -t user@mydomain.com "myscript backup_remote_db"
"myscript" - bash script, "backup_remote_db" - , , .
, , $USER script, , ...
*** 2 ******
:
db_host=$DATABASE_SERVER
echo "The DB Host is $db_host"
script:
ssh -t user@mydomain.com ". /etc/profile; myscript backup_remote_db"