Wrong executing sqlplus command on php cron job -
i have php code:
<?php define('oracle_sid', 'mydb'); define('oracle_home', '/usr/lib/oracle/11.2/client'); shell_exec('oracle_sid=' . oracle_sid); shell_exec('export oracle_sid'); shell_exec('oracle_home=' . oracle_home); shell_exec('export oracle_home'); putenv("oracle_home=".oracle_home); putenv("oracle_sid=".oracle_sid); $path = shell_exec('echo $path'); $oracle_home = shell_exec('echo $oracle_home'); $abs_path = str_replace("\n","",$path. ":" .$oracle_home . "/bin"); putenv("path=".$abs_path); echo exec('sqlplus myuser/mypass@mydb @/absolute/route/to/script.sql'); ?>
here export environment variables in order run sqlplus command. works fine when execute line command, when "cron" executes it, doesn't run sqlplus command.
i checked "exports" part on cron running "echos" on variables, , seems work fine. tried running sqlplus command adding absolute path, doesn't work either...
the corresponding line in crontab:
*/5 * * * * /usr/bin/php /home/myusr/script.php >> /home/myusr/out.txt
does know if i'm missing something??
thanks lot in advance
i found solution: executing cron loading environment of user got right profile in same instruction.
*/5 * * * * su - myusr -c '/usr/bin/php /home/myusr/script.php'
the .profile of "myusr" must set necessary environment variables.
i don't know why doesn't load environment variables executing sentences script (i tried calling ".profile" script, , didn't work either), nice if give light :)
thank you
Comments
Post a Comment