LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Setting Up Cron Jobs with SSH/Putty (https://www.linuxquestions.org/questions/linux-newbie-8/setting-up-cron-jobs-with-ssh-putty-689470/)

jmrothermel 12-09-2008 10:06 PM

Setting Up Cron Jobs with SSH/Putty
 
Ok, please I apologize in advance for my complete dumbness. I havent ever dealt with Linux before, so this whole thing is like complete greek to me.

I have a website that frequently relies on cron jobs to complete tasks. On our old hoster, I had the "Cron Manager" in the administrative suite. Unfortunately we've outgrown that hosting plan, and now moved to a VDS server. So I'm in a world I dont know. I asked my hoster how to create cron jobs and he stated I could use putty.

So, heres how far I got.

I downloaded putty and was able to connect via SSH to my website. If I type in any cron command (as I was trying to do this myself by google first) nothing happens. Im not sure if I have to be in a specific file, or what. Im so so confused.

I can post any other information that might be able to help me, but how to get that crontab command to work would be great. (Do I need to login a certain way, have certain permissions set, be in a certain folder?) That'd probably help immensly.

Again, Im so sorry for being a total Linux noob. Thanks in advance for any help!

AuroraCA 12-09-2008 10:14 PM

All cron commands for each user are located in their own crontab file. To edit the crontab file you should use the crontab command.

see: crontab man

jmrothermel 12-09-2008 10:17 PM

I guess thats where Im getting confused. If I just log into putty and start at the prompt I start at and type crontab -l or crontab -e nothing happens. It just goes to the next line prompt. So Im wondering if I have to be in a certain file to view/execute crontab commands? I was able to check where the users and deny lists would be and there is none on my site.

Im so sorry for being so stupid :(

billymayday 12-09-2008 10:31 PM

If crontab -e does nothing, maybe you need to ask the admin which user can run cron, and make sure you connect as that user.

ls /var/spool/cron

may give us hints

jmrothermel 12-10-2008 08:25 AM

Heres the reply I got from my webhoster:

To use cron, you will need to edit the file /var/spool/cron/h321760w and then type the command crontab at the SSH prompt. We do not provide any technical support for problems with cron, but it does work just fine.

So I do have that file, and I am able to edit it. What do I put in that file though? Say I have a php cron called cron.php I want to run every minute (just for example to get the hang of this).

Thank you all so much for the help!

EDITED TO ADD:

I did try to figure this out myself and I put this in the file:

Code:

#!/usr/local/bin/php
<?include("config.php")

MAILTO=myname@myserver.net
* * * * * php /var/www/html/66.84.26.31/cron.php

?>

(With the mailto just to see if it works I really dont need that - and yes to my email I just edited it out :-P)

If I type in crontab at the command prompt it tells me bad minute? *confused* Am I even anywhere near the right track here? LOL Thanks again for the help!

EDITED AGAIN:

Heres the exact error message:
Quote:

bad minute
errors in crontab file, can't install.
Failed to update crontab

jmrothermel 12-10-2008 11:24 AM

Ok I had a small breakthrough! YAYYYYYYYYYYYYYYY (LOL Im a dork :p)

So if I go into my SSH and type /var/www/html/cron.php the sql query that I have in the file executes (Which just for testing purposes is as below:)

Code:

#!/usr/bin/php -q
<?include("config.php");


                        $update = mysql_query("UPDATE `test` SET `test`='5' WHERE `id`='1'");
               

?>

So I know the cron can and does work. Now, what/where/how do I edit that stupid /var/spool/cron/h321760w file and what do I put in it? I tried editing it with my file editor to just reflect the cron ( * * * * * /var/www/html/66.84.26.31/crontest.php ) But alas that didnt work. Do I edit it through SSH with Putty?

Im so close Im finally not sitting here on the verge of tears. I just need to figure this last key out. I dont know if it helps, but Im on a VDS server which I guess is why the crontab -e didnt work? THANK YOU!

AuroraCA 12-10-2008 12:02 PM

Your first try in post #5 failed since the only content allowed in a crontab file is a comment which begins with a "#" or a line which contains a 7 field crontab entry in the following format:

Code:

#"minute"  "hour"  "day of month"  "month"  "day of week"  "user"  "command(s)"

* * * * * jmrothermel /var/www/html/66.84.26.31/crontest.php

Your last post only had 6 fields in the crontab entry.

billymayday 12-10-2008 03:20 PM

The only cron entry on my system that has the user specified is /etc/crontab. The user files in /var/spool/cron don't.

What you need to remember is that cron doesn't inherit you environment, so you path for example means nothing in cron.

You say that entering
Code:

/var/www/html/cron.php
works from the command line, but for cron you are using
Code:

* * * * * /var/www/html/66.84.26.31/crontest.php
Why aren't you using
Code:

* * * * * /var/www/html/cron.php
Does
Code:

/var/www/html/66.84.26.31/crontest.php
work from the command line?


All times are GMT -5. The time now is 11:44 AM.