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! |
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 |
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 :( |
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 |
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 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:
|
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 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! |
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)" |
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 Code:
* * * * * /var/www/html/66.84.26.31/crontest.php Code:
* * * * * /var/www/html/cron.php Code:
/var/www/html/66.84.26.31/crontest.php |
All times are GMT -5. The time now is 11:44 AM. |