Creating Cron jobs?


#1

I want to create a cron job on my account but after reading everything in the Knowledge Base on cron I still have a few questions.

  1. When does the cron job I create go into effect? I know that some other webhost will have the Cron list update at midnight and then it will add the new job you added to the list.

  2. What directory does the cron job start in? I want to have my script which is in sub-directory run. But how do I know what the path should be?


#2

Immediately (well, obviously it won’t actually run until you schedule it to run).

Not quite sure I follow - you should always use the full path with a cron job - so if the script you’re running from cron were in a subdirectory of your home dir called “bin” you’d do:

          • /home/username/bin/somescript

you can also just do:
$HOME/bin/somescript

I’d suggest reading section 5 of the crontab manual too - type man 5 crontab at the command line.


#3

I type date in telnet to see the time on the webserver and then I set the cronjob a few mins after that time. Then I place the crontab command in a file i call cron.txt. Upload it to my webser type ‘crontab cron.txt’ in telnet and then type ‘crontab -l’ to make sure its listed. This part all works. But the script never executes. However If I execute the command I have in the cronjob from telnet it works fine.

Any idea why it wont start? or maybe there is a way to have cron report errors to me?


#4

By default, any errors or output will be emailed to you (unless you’re dumping stderr and / or stdout - see another recent thread on this). It will go to the mail account corresponding to the user you’re running the crontab as.


#5

It doesnt seem to be sending any emails. Exactly how is this supose to be setup? I have this script in a sub-domain that also has a difffrnet acount name then my main site.

My subdomain is hlstats.infinity-zero.net . Any I have an email account set-up for the user hlstats@infinity-zero.net . But I dont recieve any emails.


#6

Its still not working. This is what I have:

07 15 * * * cd /home/hlstats/hlstats; perl hlstats.pl &

I wait till 15:08 and then I check to see if it started and it hasnt. Yet if I execute the following line from the shell it works fine.

cd /home/hlstats/hlstats; perl hlstats.pl &


#7

Have you tried not doing it in the background (i.e., removing the ampersand)?

What if you do:
/home/hlstats/hlstats/hlstats.pl

BTW, I’d try just setting it to every minute (* * * * *) first, make sure it’s working, and then deal with getting it to run at the right time.


#8

Still not working so I tried a diffrent thing to test.

I created a file called elf.txt and upload it to my ftp. Then I created this cron line:

          • cd /home/hlstats/hlstats; rm elf.txt

This line should delete the file. I entered this line into a txt file called cron.txt and then used crontab cron.txt and crontab -l to check and make sure it went it. That all worked. I waited a few mins and low and behold the file was STILL there. So I executed this line manually from the shell:

cd /home/hlstats/hlstats; rm elf.txt

And now the file is gone. It seems to me that something is not workin with the cronjob or the cron program itself.


#9

Do you check email for the user that’s running the crontab? If there are errors, they’ll (by default) be emailed to that user. You can either use mutt or Pine to view the mail, or view it in any IMAP client. You can send cron output elsewhere by setting MAILTO=someaddress@example.com (for example) in the crontab.

If you’re not getting any cron output via email, then something’s wrong and send a message to support.


#10

My accounts email is getting any cron reports.

How do I use the mailto?


#11

What did you use to edit your cron.txt file? Did you edit this on a Windows machine? It showed up without a line break at the end; now that I added that, it seems to be running properly (the elf.txt file got removed, anyway).

Looks like you edited it again since that with the MAILTO link in there (if there are no errors and no output, you won’t get any mail, though). Try going to the next line; better, if you know how to use vi, use crontab -e (and set $VISUAL to “nvi” in your environment; how to do this is described in other posts in this forum).

the man page for crontab is also helpful - you need to look in section 5 for the information on the format of the file itself - “man 5 crontab”.


#12

Okay. I added a new line after the command like u said and its working.

Thx for your help guys!