473,606 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP and Crontab and Current Directory

So I wrote a script and at the top it checks whether a file exists
like below

if (!file_exists(" settings.ini"))
return false;

and the crontab entry:

00 08 * * 4 /usr/local/bin/php /home/user/scripts/test.php /dev/null
2>&1

however everytime it runs via cron, it can't find the file
settings.ini because it keeps looking for it in $HOME not in $HOME/
scripts/ where test.php resides

Why? And how can I re-code it to look in the current directory not in
$HOME? I tried ./settings.ini but without success

Apr 25 '07 #1
5 2988
Rik
Euhm, check my reply to your previous post?

--
Rik Wasmus

Estimated date being able to walk again: 01-05-2007.
Less then a week, hurray!
Apr 25 '07 #2
ro*********@goo glemail.com wrote:
So I wrote a script and at the top it checks whether a file exists
like below

if (!file_exists(" settings.ini"))
return false;

and the crontab entry:

00 08 * * 4 /usr/local/bin/php /home/user/scripts/test.php /dev/null
2>&1

however everytime it runs via cron, it can't find the file
settings.ini because it keeps looking for it in $HOME not in $HOME/
scripts/ where test.php resides

Why? And how can I re-code it to look in the current directory not in
$HOME? I tried ./settings.ini but without success
You can change the working directory with chdir() near the top of your script:

#!/usr/local/bin/php -q
<?php
chdir( '/home/user/scripts' );

//...
?>

That should make file_exists() work as expected.

If it doesn't do what you want it to do, you can try instead using:

ini_set( 'include_path', '/home/user/scripts' );

To temporarily set it as the (only) include path in the ini settings.

-Mike PII
Apr 25 '07 #3
Sorry Rik, didn't notice your reply to the last one (I didn't even notice the last one).

-Mike PII
Apr 25 '07 #4
Rik
Michael Placentra II wrote:
Sorry Rik, didn't notice your reply to the last one (I didn't even
notice the last one).

Hehehe, neither did he :-)

--
Rik Wasmus

Estimated date being able to walk again: 01-05-2007.
Less then a week, hurray!
Apr 25 '07 #5
On Apr 25, 10:26 pm, Rik <luiheidsgoe... @hotmail.comwro te:
Euhm, check my reply to your previous post?
Sorry about that, didn't show up and thought I had crossposted to too
many groups and got halted by anti-spam scripts.

Anyway your advice worked however the problem is I have to edit the
script everytime I run the program via Cron

Instead after some googling I found this method of instead:

00 11 * * * cd /home/user1/files/; /usr/local/bin/php test.php

Apr 26 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3537
by: Arkascha | last post by:
Maybe someone can give me a short help with this... I got a server application in a LAMP environment doing batch tasks. A cronjob serves as a regular trigger, a metronom. The trigged processcollects a number of pending jobs to be run and typically creates a number of additional jobs to be run in future. The type of created jobs, their parameters and everything can be configured in the application. Fine... In addition I'd like to...
4
2040
by: David Bruno | last post by:
I set up a crontab using cpanel8 for the first time. It's just to run a very simple php script that sends an email and has one include() function. The first try at the crontab produced a permission denied result. I gave it the proper permissions and on the second try, the results say that there is no such file but it also shows some of the php code and says "syntax error near unexpected token" This script works perfectly fine when...
3
5355
by: Frank R. Suchy | last post by:
Hi, I want a php-script to maintain (some of) "my" cron jobs. Therefore it has to modify some crontab.txt (no problem) and has to execute crontab. But since php runs as the apache-user it cannot run "my" crontab. In general: Can a php-script run an external program under a different
3
5393
by: rbt | last post by:
How can I safely append a crontab entry to a crontab file progammatically with Python? I need to handle crontabs that currently have entries and crontabs that are empty. Also, I'd like this to work across Linux and BSD systems. Any pointers?
2
8421
by: David Garamond | last post by:
I was thinking on how one would design an optimal (performance-wise) database of large number of schedules with crontab-like semantic. There will potentially be hundreds of thousands or even millions of "crontab" entries, and there will be a query run once every minute to determine which entries are to be run for that minute. The primary goal is, of course, for the query to run as fast as possible. My first stab is, straightforward...
3
3375
by: Sandman | last post by:
I have a PHP cli script, that backups my databases, using mysqldump via system(). When logged in with SSH, and launching the script with "./backup.php", all works just as it should, but when I put it in a crontab: 00 2 * * * /home/sandman/bin/backup.php I get a mail that says:
4
3966
by: Chr1s | last post by:
How do I execute a crontab command using php (not CLI) as user Joe? I don't have any problem getting output from commands such as 'ls' using passthru and exec but I am stumped with crontab. Many thanks! Chris
2
3870
by: martijn | last post by:
H! I have made a program that is checking if a program is running or not. If the program is not running then it must start the program again. in the /etc/crontab: * * * * * root /usr/sbin/ program_prgchk in the /usr/sbin/program_prgchk:
0
1345
by: Martin Marcher | last post by:
Hello, is anyone aware of a crontab library. Possibly even more complete, something that will let me create/manipulate/delete crontab entries in a nice way and install the new crontab accordingly. I had a look at the crontab docs and never realized how complex it actually is. So before I spend time in creating such a thing maybe
0
8015
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7951
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8439
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
3977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1553
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1296
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.