LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 12-09-2008, 10:06 PM   #1
jmrothermel
LQ Newbie
 
Registered: Dec 2008
Posts: 4

Rep: Reputation: 0
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!
 
Old 12-09-2008, 10:14 PM   #2
AuroraCA
Member
 
Registered: Jul 2008
Location: Northern CA USA
Distribution: Ubuntu, Slackware, Gentoo, Fedora, Red Hat, Puppy Linux
Posts: 370

Rep: Reputation: 35
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
 
Old 12-09-2008, 10:17 PM   #3
jmrothermel
LQ Newbie
 
Registered: Dec 2008
Posts: 4

Original Poster
Rep: Reputation: 0
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
 
Old 12-09-2008, 10:31 PM   #4
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
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
 
Old 12-10-2008, 08:25 AM   #5
jmrothermel
LQ Newbie
 
Registered: Dec 2008
Posts: 4

Original Poster
Rep: Reputation: 0
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

Last edited by jmrothermel; 12-10-2008 at 08:34 AM.
 
Old 12-10-2008, 11:24 AM   #6
jmrothermel
LQ Newbie
 
Registered: Dec 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Ok I had a small breakthrough! YAYYYYYYYYYYYYYYY (LOL Im a dork )

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!
 
Old 12-10-2008, 12:02 PM   #7
AuroraCA
Member
 
Registered: Jul 2008
Location: Northern CA USA
Distribution: Ubuntu, Slackware, Gentoo, Fedora, Red Hat, Puppy Linux
Posts: 370

Rep: Reputation: 35
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.

Last edited by AuroraCA; 12-10-2008 at 12:03 PM.
 
Old 12-10-2008, 03:20 PM   #8
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
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?
 
  


Reply



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
Setting up cron jobs in Slackware 12 swampdog2002 Slackware 1 02-06-2008 08:08 PM
cron hourly, daily, cron.d jobs don't execute eggsmartha Linux - General 3 09-17-2007 06:37 PM
Cron Jobs christo512 Linux - Software 1 02-09-2006 09:19 AM
CRON Jobs scottpioso Linux - Software 63 11-28-2003 06:45 PM
cron jobs Zyanid Linux - Software 0 08-27-2002 05:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:53 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
Open Source Consulting | Domain Registration