Question about setting up a cronjob


#1

Hi DH-Community,

i am running a site at dreamhost where I provide data out of my database. I have different tables (players, teams, clubs, leagues, and so on). Those data are related to each other (a player belongs to one or more teams, a team belongs to a club and plays in a certain league, …).

Once a day I get a file with new players. This file only contains the playernumber, the name and the teamnumber. This are enough information to find out the relations to league and club with a little script.

My problem is, that i want to use a cronjob to run this script once a day. I can see the place, where i can create a new cronjob in my panel. But I did not know, what to enter. So I read all related posts in this forum. But as i am a absolute newbie to shell and my native language is not english, i am more confused than before.

I have also seen the information in the wiki, but my confusion level is already to high… :frowning:

Thats what I did so far:

  • Creating an shell user
  • Using putty to make the bin directory and entering the four command lines mentioned in the wiki.

Maybe there is somebody, that can explain me what to do and how to do it. I really would appreciate some help.

Thanks a lot in advance.
Mike

PS: forgot to mention that the script is a PHP-file.
PPS: not sure, if i have to do the shell stuff with putte and creating it in the panel or if those are two different ways for the same thing. I now entered http://www.tischtennisverein.info/cronjobscript.php in the panel, but i think this is not correct!?


#2

There was a recent post on running a PHP cron job:
http://discussion.dreamhost.com/showflat.pl?Cat=&Board=forum_troubleshooting&Number=91681&page=1&view=collapsed&sb=5&o=31&part=

Fortunately, using the Panel to set up a cron job is pretty straight forward. The catch is that since it’s a PHP script, your cronjob needs to follow the syntax in the post above. It should be something like:

/usr/local/php5/bin/php $HOME/tischtennisverein.info/cronjobscript.php

-Scott


#3

Thank you for your answer. But to be honest, now i am as confused as before.

I searched the forum and the wiki all day long and i found this article in the wiki: http://wiki.dreamhost.com/Crontab#Executing_a_PHP_Script_with_Crontabs

It sais, that when I use the Goodies Section in the panel I do not have to do the other stuff (SSH and so on) I mentioned before in my opening post.

It seem, that I only have to enter those two command lines and the cronjob is set up. But as there are only example commands I am not sure what to enter in my case.

The example in the code lookes like this:
/dh/cgi-system/php5.cgi /home/yourserver/youruser/yourdomain/pathto/yourphpscript.php

So I tried:
/dh/cgi-system/php5.cgi /home/martinellis/ttinfo_shell/www.tischtennisverein.info/cronjobs/get_player.php

I set it to run every minute (only to see the result within a minute… if it runs, I will set it to once a day), but after checking my databas, I have seen, that it still does not run.

Maybe I am really stupid in this case, but I really have never had something to do with cronjobs. Or maybe its the language barrier that does not allow me to understand. (I have to admit… my english is not the best, but usually its enough to understand).

Anyway… please please HELP one more time :wink:

Thanks
Mike

I bin ja quasi a Lichtgestalt!


#4

What I did to have a php script executed by cron :

  • I write and check a cronjob.php script, it works when I load it from the web
  • I add this line at the beginning of the cronjob.php script :
    #! /usr/local/bin/php -q
  • I put this file out of the web directories and give it permission to execute (CHMOD 711 with a ftp program)
  • I write a crontab.txt file, this file contains the cron command to execute :
    MAILTO=myemail@mydomain.com
    15 16 * * 1,3,5 /home/user/mydirectory/cronjob.php
  • I put this file in my directory out of the web structure
  • I log on my user account with SSH and tell cron to use my crontab file :
    crontab /home/user/mydirectory/crontab.txt
  • I can check the current crontab with the command :
    crontab -l

Hope this helps… I guess you may have forgotten to add the #! /usr/local/bin/php -q at the beginning of your php file ?


#5

Thanks for your answer… I begin to believe, that I am really to stupid.

  • I write and check a cronjob.php script, it works when I load it from the web
    —> no problem. I already did that and the script works fine.

  • I add this line at the beginning of the cronjob.php script :
    #! /usr/local/bin/php -q
    —> I just did that

  • I put this file out of the web directories and give it permission to execute (CHMOD 711 with a ftp program)
    —> CHMOd is no problem. But in which folder do I have to save the file?

  • I write a crontab.txt file, this file contains the cron command to execute :
    MAILTO=myemail@mydomain.com
    15 16 * * 1,3,5 /home/user/mydirectory/cronjob.php
    —> I understand the Mailto-line, but what do the numbers in the next line mean? And can I use the /home/user/ string as it is or do I have to replace home and/or user by something?

  • I put this file in my directory out of the web structure
    —> is it the same directory, that is already mentioned above?

  • I log on my user account with SSH and tell cron to use my crontab file :
    crontab /home/user/mydirectory/crontab.txt
    —> Do I only have to type in this command or are there any things to do before I type in this command?

  • I can check the current crontab with the command :
    crontab -l
    —> I understand that :slight_smile:

I am a little bit confused. Some sources say, I do not have to use the shell and crontab thing and can do it via the panel only and other sources say: “make the shell stuff”. Are this two different ways to get the same result or do I have to do both things to make it run? Some sources say, write that special line in front of the cronjobfile and other sources do not mention that point…

As I do not have any knowledge and experience with the shell thing, I would prefer the panel thing. Dont want to mess something up (Customers tend to leave pretty fast as I am offering information, that can also be found on other sites. So when the site is down, i am usually loosing members very fast). Can somebody tell me what to do (no more shell stuff. There is a panel solution and I wanna use this) to make the script http://www.tischtennisverein.info/cronjobs/get_player.php run. I am on server martinellis and the shelluser is called ttinfo_shell. I do not have more knowledge about that stuff.

Well… I think its better to use a free cronjob service in the internet, where I only have to enter the URL of the file i want to run at a certain time and klick “Okay”. The DH method is ways to complex for me.

Nevertheless thank you all for your help.
Mike

I bin ja quasi a Lichtgestalt!


#6

Try putting this in your crontab in the Panel:

/usr/bin/curl www.tischtennisverein.info/cronjobs/get_player.php

If it’s a valid PHP script, then it’ll run. For practice, you can run it manually from the command line when you log in via PuTTY.

-Scott


#7

[/quote]

Where you want, I took as example
home/user/mydirectory/

Usually your website is in :
home/user/mydomain.com/

That’s why I call it “out of the web structure”

[/quote]

These say when to run it. You should find easily documents for the syntax for this. In my example, 15 16 * * 1,3,5 means “every first, third and fifth day of the week at 16 hours and 15 minutes”.
*/2 * * * * means “every two minutes”

[/quote]

home is always home, but user has to be replaced by your user

[/quote]

Yes, but it’s your choice

[/quote]

You log in, and then you type it as shown, but after replacing ‘user’ and ‘mydirectory’ with your own data

[/quote]

I understand because I’ve been there. And that’s why I’m here trying to explain. After your first success, you will find it very easy, believe me : I’ve been there :slight_smile:


#8

Hello sdayman,

that was exactly what i was looling for. Thank you so much for your help.

I do not really understand what the “curl” means, but as long as it is running i dont wanna know :slight_smile:

Thank you also to all others who helped with information and tipps about that topic.

Regards
Mike

I bin ja quasi a Lichtgestalt!


#9

curl is just a manual web client that grabs a page just like your browser does. Glad it worked out.

-Scott