• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

Executing PHP script from commandline

I need to set the following up as a cron job.

/usr/bin/php {PATH_TO_SCRIPT}/schedule_cron_user.php

So, I have the path to the script.  But, when I attempt to execute it, I get Permission Denied even if logged on with su -

can someone help me?

thanks
0
OnsiteSupport
Asked:
OnsiteSupport
  • 6
  • 5
  • 3
  • +4
1 Solution
 
sjklein42Commented:
Have you set Execute privilege on the php file?
0
 
OnsiteSupportAuthor Commented:
nope....unfortunately, I don't know what that is.  can you give me some more info?
0
 
Dave BaldwinFixer of ProblemsCommented:
Are you getting that from cron?   Can you run the script in your own home directory?  What does the script do?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
sjklein42Commented:
Add Execute permission:

chmod a+x {PATH_TO_SCRIPT}/schedule_cron_user.php

Open in new window

0
 
Hugh McCurdyCommented:
My php scripts are 644.  You don't need a execute bit.

I suspect the problem might be coming from the script itself.  Do you get the error if you run the script from the command line?

# php {PATH_TO_SCRIPT}/schedule_cron_user.php

Of course, replacing {PATH_TO_SCRIPT} with the actual path.


If that fails with permission denied, then I'd add an echo statement to the top of the script to see if it executes the echo statement.  If so, I'd add more echo statements to see how far the script gets before it says permission denied.

Either way, I suggest you report back what happens.
0
 
Ahmed MerghaniCommented:
Try to copy "schedule_cron_user.php" to directory "/usr/bin/php" and run command:

/usr/bin/php schedule_cron_user.php

Open in new window


0
 
OnsiteSupportAuthor Commented:
Mccurdy-
Executing the script at the command line errors out all over.  This is a step bettern than permission denied after chmod to Execute.

0
 
Hugh McCurdyCommented:
Would it be possible to share the contents of the script and the error messages?
0
 
OnsiteSupportAuthor Commented:

I had it executing...now I get invalid command no matter where I copy the file.
schedule-cron.php
0
 
OnsiteSupportAuthor Commented:
Here is error messages: schedule-cron-errors.txt
0
 
Dave BaldwinFixer of ProblemsCommented:
The 'echo' on line 2 does not have ';' at the end.  I don't think trying to load Joomla from the command line is going to work well either.
0
 
Dave BaldwinFixer of ProblemsCommented:
Some of those errors occur because you are not executing 'php' first and letting it run the script.
0
 
OnsiteSupportAuthor Commented:
LMAO....you're talking to a Windows person.  I'm barkin up the wrong tree here.  If I launch it thru a cron job, it still doesn't have the desired effect.  But, I have no idea how to troubleshoot it.

This is supposed to be schedule handler for SQL 2 Excel.  This runs a query against mysql db and dumps it into an Excel file and is supposed to send it via email.  I know the query is running and tested properly, but I can't get the cron job to kick off the schedule that is setup in SQL 2 Excel.

Thanks
0
 
Dave BaldwinFixer of ProblemsCommented:
I doubt that it will work from the command because it is intended to be run thru Joomla on a web server.  Running it on the command line changes an awful lot of things.  I don't think Joomla will run from the command line.  The internals links are expecting a web server and a domain to run on.

For the command line use, you need to find a stand-alone script that doesn't require Joomla or the web server.
0
 
Hugh McCurdyCommented:
The correct way to run a command line PHP script is

$ php myscript.php

However, this script doesn't appear to be setup for command line operation.  (The $_SERVER variable)

What is the desired purpose of this script?
0
 
OnsiteSupportAuthor Commented:
SQL2Excel has a scheduler that is supposed to send an attachment over email as the result of a SQL query against mysql tables.  Here is the document from the vendor:

 http---support.joomla-r-us.pdf
0
 
zicevaCommented:
You should try something like this (it should work in command line and in cron):

wget http://domain.tld/path/to/script.php?whatever_variables_it_might_need -O /dev/null
0
 
Dave BaldwinFixer of ProblemsCommented:
Ok, that says they have set it up to run properly.  Go get the original "schedule_cron.php" file.  Since I don't know exactly what is supposed to be there, it would be hard to troubleshoot the one you have posted.  Since SQL2Excel is a paid for software, I can't get in to get it for you.

Note that the entire command shown in the PDF is:

/usr/bin/php /home/xxxx/public_html/joomla/administrator/components/com_sql2excel/helpers/schedule_cron.php
>> /dev/null 2>&1

If the script is correct, you need all of that for it to run properly.

"/usr/bin/php" is where PHP is expected to be found and they show how to find it if it is not.  "which php"

"/dev/null 2>&1" takes care of dumping the HTML output from Joomla since it needs to go 'somewhere'.
0
 
AdriancCommented:
Hi, here is how I do that.

Follow this steps:

1. put this code before everything else in your script

#!/usr/bin/php -q

Open in new window


2. chmod +x yourscript.php
3. run your script like a normal executable

./yourscript.php

Open in new window


if you want to run your script form php you can use exec and disown like this

exec("yourscript.php &>/dev/null & disown")

Open in new window


I'm using this for a long time and it works 100% so please let me know if you have problems.

Bye.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 5
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now