473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Cron Job Confusion

TheServant
1,168 Expert 1GB
Hey guys, here is my PHP code I want to run in a cron job:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. mysql_connect ("localhost", "username", "userpass") or die ('I cannot connect to MySQL because: ' . mysql_error());
  3. echo('Connected to MySQL<br />');
  4.  
  5. mysql_select_db ("dbname") or die('I cannot connect to the database because: ' . mysql_error());
  6. echo('Connected to Database<br />');
  7.  
  8. mysql_query( "
  9.     UPDATE users...
  10.     " ) or die(mysql_error());
  11. ?>
I get the following error in the output being sent to my email:
Expand|Select|Wrap|Line Numbers
  1. /home/user/public_html/.../file.php: line 1: ?php
  2.   : No such file or directory
  3.   /home/user/public_html/.../file.php: line 2: syntax error near unexpected token `"localhost",'
  4.   /home/user/public_html/.../file.php: line 2: `mysql_connect ("localhost", "username", "userpass") or die ('I cannot connect to MySQL because: ' . mysql_error()); '
I know it's running, but I don't know why it's not working? There is no update so it's not getting to the function, but the path is all correct? Does that first erro mean I should not have <?php in my cron job file?
Jan 29 '09 #1
2 1321
Atli
5,058 Expert 4TB
Hi.

I'm guessing the problem is that the code is not being executed as PHP, but rather as shell commands.

You need tell the shell that the code is meant to be executed using the PHP parser.
That can be done by adding the path the the PHP parser as the first line of the file:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/php
  2.  
  3. <?php
  4.   // Do something.
  5. ?>
If you don't know the path the the PHP executable, try doing:
Expand|Select|Wrap|Line Numbers
  1. whereis php
That should show you where it is.
Jan 29 '09 #2
TheServant
1,168 Expert 1GB
Thanks Atli. I spoke with support and they said a very similar thing to what you said. Although I cannot try it right now, it does make sense what you (and they) said, so thanks for your reply.
Jan 29 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: sherryonline | last post by:
i have a page and i need that page to be called every day at 12:00 that page is going to connect to the database fetch some emails and will start mailing them how i am goning to do this.
4
by: vagrantbrad | last post by:
I'm using python 2.4 running on Fedora Core 4. I have written a python program called ipscan.py that checks the external ip address of my cable internet connection, and on change, will update the...
3
by: the.natalie | last post by:
Hi. I am a newbie to mysql, cron, and shell scripting, so please bear with me. I have a script that is used for updating an image directory based on contents in a database. The script does the...
5
by: jcor | last post by:
Hi, I'm trying to run my first cron job, probably it's missing something. I created a perl script just to test, it's called "teste" !/usr/bin/perl open(DATA,">>/home/joao/files/output"); @Now...
4
by: Phil | last post by:
I have a php script that queries some Oracle DB and outputs a single line of plain text with <brat the end for each query. This is Apache2, php4.4.8 and Oracle Instant Client 10.1.0.5 all on CentOS...
5
by: Lawrence Krubner | last post by:
Do any problems come up when using a static variable in a cron job? Assuming the cron job is called every 5 minutes for one year. Assume I've got an array that stores the names of which users are...
4
by: Stephen Cattaneo | last post by:
Hello all, I am attempting to execute an automated test (written in Python) via cron. I have to check the HOSTNAME variable as part of the test, oddly under cron the HOSTNAME environment...
0
by: Cameron Simpson | last post by:
On 17Aug2008 21:25, John Nagle <nagle@animats.comwrote: Because $HOSTNAME is a bash specific variable, set by bash but NOT EXPORTED! Like $0 and a bunch of other "private" variables, subprocesses...
1
by: Karthik Gurusamy | last post by:
Hi, I'm working on a cron like functionality for my application. The outer loops runs continuously waking every x seconds (say x=180, 300, ..). It needs to know what events in cron has expired...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.