LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-05-2011, 04:21 AM   #1
alphakurt
LQ Newbie
 
Registered: Mar 2011
Posts: 2

Rep: Reputation: 0
help setting up a cronjob


hi all

new to the forum and also to linux.

i have a site where I need to run a couple of php scripts every day..therefore I was thinking to setup a cronjob to do this. Unfortunately I get a whole bunch of errors trying to do so.

I can execute the php scripts via a command line without problem, one example would be

php /home/site/domains/stie.be/public_html/admin/cronjobs/cronjob_daily_ssh.php

however when i enter this command as such in a cronjob I get an error saying php command not found ( or something similar , doing this out of memory)

I tried to add the full path to the php command, but also this doenst work

the best workaround I found was to execute the php scripts with a lynx - dump command, but obviously this is not the right way

help would be very very much appreciated...
 
Old 04-05-2011, 05:11 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Welcome to LQ

How did you create the cronjob?
Please post the cronjob you created.
Quote:
I tried to add the full path to the php command, but also this doenst work
Did you get error messages?

Kind regards
 
Old 04-05-2011, 07:41 AM   #3
alphakurt
LQ Newbie
 
Registered: Mar 2011
Posts: 2

Original Poster
Rep: Reputation: 0
crontab created as a user with command : crontab -uuser -e
then just added jobs as the one above : php /home/site/domains/stie.be/public_html/admin/cronjobs/cronjob_daily_ssh.php


I got an error saying php command not found are not allowed or something similar.
 
Old 04-05-2011, 07:47 AM   #4
rahul_dubeyin
Member
 
Registered: Apr 2011
Posts: 34

Rep: Reputation: 12
Quote:
Originally Posted by alphakurt View Post
crontab created as a user with command : crontab -uuser -e
then just added jobs as the one above : php /home/site/domains/stie.be/public_html/admin/cronjobs/cronjob_daily_ssh.php


I got an error saying php command not found are not allowed or something similar.
remove php from the line else give full path to php executable like /bin/bash. you can locate the path using locate command.
 
Old 04-05-2011, 07:50 AM   #5
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
maybe some usefull links:

crontab
Locate
 
Old 04-05-2011, 10:39 AM   #6
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Quote:
I got an error saying php command not found are not allowed or something similar.
Please give the exact error.
Does the user who created the cronjob has the correct rights to run
Code:
cronjob_daily_ssh.php
Give the whole path to php, and create the cronjob as root
use
Code:
/usr/bin/php /home/site/domains/stie.be/public_html/admin/cronjobs/cronjob_daily_ssh.php  > /tmp/log.txt 2>&1
Kind regards

Last edited by repo; 04-05-2011 at 10:42 AM.
 
Old 04-05-2011, 10:43 AM   #7
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 394

Rep: Reputation: 61
If you put the line: -

Code:
#!/usr/bin/php
at the top of your php file (assuming that is the location of the php intepreter) and then set the script as executable with: -

Code:
chmod u+x yourphpfile.php
Then enter your crontab with

Code:
crontab -e
and add: -

Code:
0 2 * * * /home/site/domains/stie.be/public_html/admin/cronjobs/cronjob_daily_ssh.php
This will run at 2am.
 
Old 04-05-2011, 10:45 AM   #8
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Quote:
you can locate the path using locate command.
The best way to find the path for a command is
Code:
whereis command
locate will only work if the database is update using updatedb as root.

Kind regards
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cronjob doing it twice why? joesto Linux - Newbie 4 11-17-2010 02:36 PM
Cronjob..... milindpk Linux - Newbie 6 05-06-2010 06:52 PM
Setting cronjob time interval to a small number mohtasham1983 Linux - General 4 09-18-2008 10:28 PM
Cronjob engnet Linux - Networking 6 03-03-2004 09:21 AM
Su in a cronjob michedlp Programming 3 11-06-2003 08:30 AM


All times are GMT -5. The time now is 01:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration