PDA

View Full Version : Cron Jobs and SSH



abomahdy
03-27-2006, 03:27 PM
Hi my friends,

This is my first post and i'am Novice on how to use SSH Comands or to edit Cron Jobs on SSH comands.

I am using the SecureCRT 5.0 to comunicate with the Server, i have create the connection, After that i am stock; i don't know what should i do, and how to create the Cron Jobs or how to begin.

Please guys if anyone can just help me step by step only to make the Cron Jobs work fine or to give me some advices to how begin with this SSH.

Thx
Samer

wildjokerdesign
03-27-2006, 05:07 PM
The command to edit cron is:

editcron -e
Now what you put in that file depends on what you are doing and there are millions of choices. :) Here is a Newbie: Intro to cron (http://www.unixgeeks.org/security/newbie/unix/cron-1.html). That was just the first result I found in Google useing "Cron" as a search word.

Try a search of "Edit Cron" on the forum and you will find other threads that have been posted on the subject as it relates to a WestHost account.

abomahdy
03-28-2006, 05:12 AM
The command to edit cron is:

editcron -e
Now what you put in that file depends on what you are doing and there are millions of choices. :) Here is a Newbie: Intro to cron (http://www.unixgeeks.org/security/newbie/unix/cron-1.htm). That was just the first result I found in Google useing "Cron" as a search word.

Try a search of "Edit Cron" on the forum and you will find other threads that have been posted on the subject as it relates to a WestHost account.

Thx for your help bro, i want to ask, to get the command i have to use the WGET option to the specific file?

wildjokerdesign
03-28-2006, 07:55 AM
I use Putty for SSH and not SecureCRT. Unless there is something different with SecureCRT all you should have to do is issue the command at the prompt. My information on this comes from the forum here and not from practical use since I have never had the need to add a cron job to the existing ones. I have never seen anyone mention haveing to use WGET.

abomahdy
03-28-2006, 08:32 AM
I use Putty for SSH and not SecureCRT. Unless there is something different with SecureCRT all you should have to do is issue the command at the prompt. My information on this comes from the forum here and not from practical use since I have never had the need to add a cron job to the existing ones. I have never seen anyone mention haveing to use WGET.
Thx for your help

i have type it like this (" */15 * * * * php /var/www/my.cron.php ")

wildjokerdesign
03-28-2006, 08:44 AM
Ahh I see what you are doing... well kind of. :) I think there is something you have to do to get cron to run a php file. Seems I remember a thread on it somewhere. If I can find it I will post a link here.

allyn
03-28-2006, 08:52 AM
Thx for your help

i have type it like this (" */15 * * * * php /var/www/my.cron.php ")

you probably need the full path to php. it is /usr/local/bin/php on my vds.

wildjokerdesign
03-28-2006, 09:12 AM
Thanks allyn that looks like that is what is needed. :) In fact reading some of the other post on this I think the full line that would need to be added would be something like this:

*/15 * * * * /usr/local/bin/php /var/www/my.cron.php >/dev/null 2>&1

Now what I have added to the end >/dev/null 2>&1 may not be needed in this case but I know that others have used it when running php scripts via cron.

abomahdy
03-28-2006, 09:55 AM
Thanks allyn that looks like that is what is needed. :) In fact reading some of the other post on this I think the full line that would need to be added would be something like this:

*/15 * * * * /usr/local/bin/php /var/www/my.cron.php >/dev/null 2>&1

Now what I have added to the end >/dev/null 2>&1 may not be needed in this case but I know that others have used it when running php scripts via cron.
Ok, but case i want to send e-mail from the crontabs how it's can be done, to confirm that the cron jobs it's raning correctly

wildjokerdesign
03-28-2006, 10:22 AM
I would think that would be best done by the php script itself. Not sure what that php script does but you could add to it somplace a call to sendmail to send you an email confirming what has happened. I can't really give you specifics since I don't know what the php script does.

abomahdy
03-28-2006, 10:32 AM
I would think that would be best done by the php script itself. Not sure what that php script does but you could add to it somplace a call to sendmail to send you an email confirming what has happened. I can't really give you specifics since I don't know what the php script does.
I has an H-Sphere hosting account in other server, and in the crontabs i had the option to type my e-mail address for error or woking cron command, like if the path of the file to do that job it's error it send an e-mail informing the error notice and vice-versa.

By doing that on H-Sphere CP, it's very easy, only you have to insert the e-mail and the Cron jobs fields to make the file works

The file.php that i want it to run every 15 minutos it's cron.php, for sending e-mail from 1-2-all Brodacast www.activecampain.com

with SSH it's different i have to program that, i'll never done that in my life, and it always have the first time.

I Hope that you understand what i mean, and sorry for my English

wildjokerdesign
03-28-2006, 10:52 AM
Ok in theroy a cron job will send any output that a script generates to the email account of the user who created it. I belive that is the reason for adding >/dev/null to the cron job so that it will not send the email. You could try to remove that and use just:

*/15 * * * * /usr/local/bin/php /var/www/my.cron.php

allyn
03-28-2006, 11:13 AM
the ">/dev/null 2>&1" says to throw away any output the command might generate.

if you want email, leave it off and cron will email you any output that the command generates.

wildjokerdesign
03-28-2006, 11:29 AM
allyn, If for some reason the php script being run does not give any output... i.e. it only sends out email and never sends anything useing echo or print... then would notheing be emailed? That is what I can't quite determin. I have set a test cron job up useing the example cron sent to a php scirpt that simply prints "test" to see what happens. :) About time for me to check emails and see what is sent.

allyn
03-28-2006, 12:47 PM
ok i have to take back everything i said. westhost seems to have their cron configured so that it never sends email. i was basing my comments on the standard features of cron.

wildjokerdesign
03-28-2006, 01:49 PM
Yes I think you are correct allyn since I have yet to recieve anything. :) Really if the php script that you are setting up cron to run sends out emails then you should know if it is not working... if it does not work then know emails would be sent. :)

jalal
03-29-2006, 01:17 AM
Try putting:
MAILTO=emailaddy

at the top of the crontab.

abomahdy
03-29-2006, 05:25 AM
Try putting:
MAILTO=emailaddy

at the top of the crontab.

But it send e-mail for what account, i mean did it send to the account that i have registered when i make the purchase of my account or do i have to insert other e-mail account

:) Salam

wildjokerdesign
03-29-2006, 07:44 AM
You need to replace emailaddy with the email address you want things sent to. :) I had read that on one site but was not sure if it would work with our VPS set up or not.

heehaa
06-04-2006, 08:13 PM
I have followed the directions in this post..

I am trying to set up a path for froogle feeder

Here is the path I set up
0 22 * * * /usr/local/bin/php /var/www/html/admin/froogle.php


when I hit enter , nothing happens. DO I have to enter anything special at the end of the command

wildjokerdesign
06-05-2006, 07:59 AM
When you logged in via SSH did you first issue the following command?
editcron -e

If so it should have opened up PICO which is an editor and you should see the current cron jobs. By default all you should see is:

53 0 * * * /bin/logrotate /etc/logrotate.conf 2>&1 > /dev/null

Use your arrow buttons to move the cursor to the next line then enter your cron job:

0 22 * * * /usr/local/bin/php /var/www/html/admin/froogle.php

If you look at the bottom of the screen you should see some "symbols" with words next to them. i.e ^G Get Help The ^G means you hold the Ctrl key while pressing G. Below that you should see ^X Exit. If you hit Cntrl E then you will exit the program PICO and it will ask you if you want to save the changes you made. Simply follow the prompts.

heehaa
06-06-2006, 03:07 PM
When you logged in via SSH did you first issue the following command?

If so it should have opened up PICO which is an editor and you should see the current cron jobs. By default all you should see is:

53 0 * * * /bin/logrotate /etc/logrotate.conf 2>&1 > /dev/null

Use your arrow buttons to move the cursor to the next line then enter your cron job:

0 22 * * * /usr/local/bin/php /var/www/html/admin/froogle.php

If you look at the bottom of the screen you should see some "symbols" with words next to them. i.e ^G Get Help The ^G means you hold the Ctrl key while pressing G. Below that you should see ^X Exit. If you hit Cntrl E then you will exit the program PICO and it will ask you if you want to save the changes you made. Simply follow the prompts.


I didnt know how to save the change....thanks that clarifies everything. How do I make the cron send me an email once it executes itself

wildjokerdesign
06-06-2006, 08:50 PM
Not sure if anyone has gotten that to work. Jalal suggested setting MAILTO=emailaddy. Have you tried that? The other option would be as suggested eariler to have the froggle.php script send you an email once it is completed. Can't really give you details since not sure how the script works but if you check php.net you should be able to find the basics of sending an email with php.