Johnny Hughes
2012-Nov-12 18:33 UTC
[CentOS] Unable to lauch php-script to truncate database
On 11/12/2012 12:38 PM, Johan Vermeulen wrote:> Dear All, > > we have some Nubuilder databases on a Centos6.3 server: > > [root at caw-server2 db]# ls /var/www/html/nubuilder/db > reg_begeleidingsteam reg_jww_archief reg_personeel reg_straathoekwerk > reg_bib reg_jww_dossiers reg_resident reg_vrijwilligers > reg_drughulp reg_jww_dvd reg_signaleren > reg_jac_activiteit reg_onthaal reg_sollicitatie > > in each database I have placed a executable file cron.php > > ------------------------------------------------------------------------------------------------------------------- > > <?php > > include "./config.php"; //nuBuilder config file > $conn = mysql_connect($DBHost, $DBUser, $DBPassword); > mysql_select_db($DBName,$conn); > > /************************************************************** > emptying zzsys_trap and zzsys_variable tables > **************************************************************/ > $sql = "TRUNCATE TABLE zzsys_trap"; > mysql_query($sql); > $sql = "TRUNCATE TABLE zzsys_variable"; > mysql_query($sql); > > /************************************************************** > Deleting temp tables > **************************************************************/ > $result=mysql_query("SHOW TABLES FROM $DBName ") or die(mysql_error()); > if(mysql_num_rows($result)>0) > { > while($row=mysql_fetch_row($result)) > { > if(substr($row[0], 0, 3) === '___' && strrev(substr($row[0], 0, > 3) === '___')) > { > $sql = "DROP TABLE $row[0]"; > mysql_query($sql); > } > } > } > ?> > > ------------------------------------------------------------------------------------------------------------------------------ > > for each file I can easily execute the file cron.php : > > [root at caw-server2 reg_bib]# php cron.php > > with the desired effect. > > *However *when I try to execute the cron.php files from a script : > > ---------------------------------------------------------------------------------------------------------------------------- > > #!/bin/bash > for i in `ls /var/www/html/nubuilder/db` > do > php /var/www/html/nubuilder/db/$i/cron.php > done > exit 0 > > ------------------------------------------------------------------------------------------------------------------------------ > > or just try to execute the script from an absolute path: > [root at caw-server2 jvermeulen]# php > /var/www/html/nubuilder/db/reg_bib/cron.php > PHP Warning: include(./config.php): failed to open stream: No such file > or directory in /var/www/html/nubuilder/db/reg_bib/cron.php on line 3 > PHP Warning: include(): Failed opening './config.php' for inclusion > (include_path='.:/usr/share/pear:/usr/share/php') in > /var/www/html/nubuilder/db/reg_bib/cron.php on line 3 > PHP Notice: Undefined variable: DBHost in > /var/www/html/nubuilder/db/reg_bib/cron.php on line 4 > PHP Notice: Undefined variable: DBUser in > /var/www/html/nubuilder/db/reg_bib/cron.php on line 4 > PHP Notice: Undefined variable: DBPassword in > /var/www/html/nubuilder/db/reg_bib/cron.php on line 4 > > I get a shipload of EM. > > I don't understand why this works but not from an absolute path. > > Any help would be greatly appreciated. > > greetings, J. >include "./config.php"; <==that is only working from within the correct directory -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 262 bytes Desc: OpenPGP digital signature URL: <http://lists.centos.org/pipermail/centos/attachments/20121112/755e8c9f/attachment-0001.sig>
Johan Vermeulen
2012-Nov-12 18:38 UTC
[CentOS] Unable to lauch php-script to truncate database
Dear All, we have some Nubuilder databases on a Centos6.3 server: [root at caw-server2 db]# ls /var/www/html/nubuilder/db reg_begeleidingsteam reg_jww_archief reg_personeel reg_straathoekwerk reg_bib reg_jww_dossiers reg_resident reg_vrijwilligers reg_drughulp reg_jww_dvd reg_signaleren reg_jac_activiteit reg_onthaal reg_sollicitatie in each database I have placed a executable file cron.php ------------------------------------------------------------------------------------------------------------------- <?php include "./config.php"; //nuBuilder config file $conn = mysql_connect($DBHost, $DBUser, $DBPassword); mysql_select_db($DBName,$conn); /************************************************************** emptying zzsys_trap and zzsys_variable tables **************************************************************/ $sql = "TRUNCATE TABLE zzsys_trap"; mysql_query($sql); $sql = "TRUNCATE TABLE zzsys_variable"; mysql_query($sql); /************************************************************** Deleting temp tables **************************************************************/ $result=mysql_query("SHOW TABLES FROM $DBName ") or die(mysql_error()); if(mysql_num_rows($result)>0) { while($row=mysql_fetch_row($result)) { if(substr($row[0], 0, 3) === '___' && strrev(substr($row[0], 0, 3) === '___')) { $sql = "DROP TABLE $row[0]"; mysql_query($sql); } } } ?> ------------------------------------------------------------------------------------------------------------------------------ for each file I can easily execute the file cron.php : [root at caw-server2 reg_bib]# php cron.php with the desired effect. *However *when I try to execute the cron.php files from a script : ---------------------------------------------------------------------------------------------------------------------------- #!/bin/bash for i in `ls /var/www/html/nubuilder/db` do php /var/www/html/nubuilder/db/$i/cron.php done exit 0 ------------------------------------------------------------------------------------------------------------------------------ or just try to execute the script from an absolute path: [root at caw-server2 jvermeulen]# php /var/www/html/nubuilder/db/reg_bib/cron.php PHP Warning: include(./config.php): failed to open stream: No such file or directory in /var/www/html/nubuilder/db/reg_bib/cron.php on line 3 PHP Warning: include(): Failed opening './config.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/nubuilder/db/reg_bib/cron.php on line 3 PHP Notice: Undefined variable: DBHost in /var/www/html/nubuilder/db/reg_bib/cron.php on line 4 PHP Notice: Undefined variable: DBUser in /var/www/html/nubuilder/db/reg_bib/cron.php on line 4 PHP Notice: Undefined variable: DBPassword in /var/www/html/nubuilder/db/reg_bib/cron.php on line 4 I get a shipload of EM. I don't understand why this works but not from an absolute path. Any help would be greatly appreciated. greetings, J. -- Johan Vermeulen IT-medewerker Caw De Kempen johan.vermeulen at cawdekempen.be Opensource Software is the future.
Keith Roberts
2012-Nov-12 20:12 UTC
[CentOS] Unable to lauch php-script to truncate database
On Mon, 12 Nov 2012, Johan Vermeulen wrote:> To: CentOS mailing list <centos at centos.org> > From: Johan Vermeulen <jvermeulen at cawdekempen.be> > Subject: [CentOS] Unable to lauch php-script to truncate database > > Dear All, > > we have some Nubuilder databases on a Centos6.3 server: > > [root at caw-server2 db]# ls /var/www/html/nubuilder/db > reg_begeleidingsteam reg_jww_archief reg_personeel reg_straathoekwerk > reg_bib reg_jww_dossiers reg_resident reg_vrijwilligers > reg_drughulp reg_jww_dvd reg_signaleren > reg_jac_activiteit reg_onthaal reg_sollicitatie > > in each database I have placed a executable file cron.php > > ------------------------------------------------------------------------------------------------------------------- > > <?php > > include "./config.php"; //nuBuilder config file > $conn = mysql_connect($DBHost, $DBUser, $DBPassword); > mysql_select_db($DBName,$conn); > > /************************************************************** > emptying zzsys_trap and zzsys_variable tables > **************************************************************/ > $sql = "TRUNCATE TABLE zzsys_trap"; > mysql_query($sql); > $sql = "TRUNCATE TABLE zzsys_variable"; > mysql_query($sql); > > /************************************************************** > Deleting temp tables > **************************************************************/ > $result=mysql_query("SHOW TABLES FROM $DBName ") or die(mysql_error()); > if(mysql_num_rows($result)>0) > { > while($row=mysql_fetch_row($result)) > { > if(substr($row[0], 0, 3) === '___' && strrev(substr($row[0], 0, > 3) === '___')) > { > $sql = "DROP TABLE $row[0]"; > mysql_query($sql); > } > } > } > ?> > > ------------------------------------------------------------------------------------------------------------------------------ > > for each file I can easily execute the file cron.php : > > [root at caw-server2 reg_bib]# php cron.php > > with the desired effect. > > *However *when I try to execute the cron.php files from a script : > > ---------------------------------------------------------------------------------------------------------------------------- > > #!/bin/bash > for i in `ls /var/www/html/nubuilder/db` > do > php /var/www/html/nubuilder/db/$i/cron.php > done > exit 0 > > ------------------------------------------------------------------------------------------------------------------------------ > > or just try to execute the script from an absolute path: > [root at caw-server2 jvermeulen]# php > /var/www/html/nubuilder/db/reg_bib/cron.php> PHP Warning: include(./config.php): failed to open stream: No such file > or directory in /var/www/html/nubuilder/db/reg_bib/cron.php on line 3> PHP Warning: include(): Failed opening './config.php' for inclusion > (include_path='.:/usr/share/pear:/usr/share/php') inHello Johan. Looks like you are trying to include files outside of your include_path settings as above. To include a php file, it has to be within the paths set in the include_path directive. Try changing your include path to the following: include_path='.:/usr/share/pear:/usr/share/php:/var/www/html/nubuilder/db' see if that does the trick. Keith ----------------------------------------------------------- Websites: http://www.karsites.net http://www.php-debuggers.net http://www.raised-from-the-dead.org.uk All email addresses are challenge-response protected with TMDA [http://tmda.net] -----------------------------------------------------------
Mark LaPierre
2012-Nov-13 00:30 UTC
[CentOS] Unable to lauch php-script to truncate database
On 11/12/2012 01:38 PM, Johan Vermeulen wrote:> Dear All, > > we have some Nubuilder databases on a Centos6.3 server: > > [root at caw-server2 db]# ls /var/www/html/nubuilder/db > reg_begeleidingsteam reg_jww_archief reg_personeel reg_straathoekwerk > reg_bib reg_jww_dossiers reg_resident reg_vrijwilligers > reg_drughulp reg_jww_dvd reg_signaleren > reg_jac_activiteit reg_onthaal reg_sollicitatie > > in each database I have placed a executable file cron.php > > ------------------------------------------------------------------------------------------------------------------- > > <?php > > include "./config.php"; //nuBuilder config file > $conn = mysql_connect($DBHost, $DBUser, $DBPassword); > mysql_select_db($DBName,$conn); > > /************************************************************** > emptying zzsys_trap and zzsys_variable tables > **************************************************************/ > $sql = "TRUNCATE TABLE zzsys_trap"; > mysql_query($sql); > $sql = "TRUNCATE TABLE zzsys_variable"; > mysql_query($sql); > > /************************************************************** > Deleting temp tables > **************************************************************/ > $result=mysql_query("SHOW TABLES FROM $DBName ") or die(mysql_error()); > if(mysql_num_rows($result)>0) > { > while($row=mysql_fetch_row($result)) > { > if(substr($row[0], 0, 3) === '___'&& strrev(substr($row[0], 0, > 3) === '___')) > { > $sql = "DROP TABLE $row[0]"; > mysql_query($sql); > } > } > } > ?> > > ------------------------------------------------------------------------------------------------------------------------------ > > for each file I can easily execute the file cron.php : > > [root at caw-server2 reg_bib]# php cron.php > > with the desired effect. > > *However *when I try to execute the cron.php files from a script : > > ---------------------------------------------------------------------------------------------------------------------------- > > #!/bin/bash > for i in `ls /var/www/html/nubuilder/db` > do > php /var/www/html/nubuilder/db/$i/cron.php > done > exit 0 > > ------------------------------------------------------------------------------------------------------------------------------ > > or just try to execute the script from an absolute path: > [root at caw-server2 jvermeulen]# php > /var/www/html/nubuilder/db/reg_bib/cron.php > PHP Warning: include(./config.php): failed to open stream: No such file > or directory in /var/www/html/nubuilder/db/reg_bib/cron.php on line 3 > PHP Warning: include(): Failed opening './config.php' for inclusion > (include_path='.:/usr/share/pear:/usr/share/php') in > /var/www/html/nubuilder/db/reg_bib/cron.php on line 3 > PHP Notice: Undefined variable: DBHost in > /var/www/html/nubuilder/db/reg_bib/cron.php on line 4 > PHP Notice: Undefined variable: DBUser in > /var/www/html/nubuilder/db/reg_bib/cron.php on line 4 > PHP Notice: Undefined variable: DBPassword in > /var/www/html/nubuilder/db/reg_bib/cron.php on line 4 > > I get a shipload of EM. > > I don't understand why this works but not from an absolute path. > > Any help would be greatly appreciated. > > greetings, J. >Are you changing your active directory to /var/www/html/nubuilder/db in your shell script first? It looks like your shell script is getting a listing of that directory and then trying to execute your PHP script in that directory which is failing because the parent process that called the PHP script is not currently in the directory where the PHP script is trying to find the files it is supposed to be working with. See where it says, "failed to open stream: No such file"? -- _ ?v? /(_)\ ^ ^ Mark LaPierre Registerd Linux user No #267004 https://linuxcounter.net/ ****