toggle background image
CronJobs
Some navigation will not work unless JavaScript is enabled
 All Links: Showv | Hide^ 

ITP Help

Special Requests

Dates/Hours v

Curriculum v

ITP Resources v

Off Floor Resources v

Tech Notes v

ITP Community v

Showing Work v

Thesis v

Servers v

ITP Policies v

Orientation/Registration v







Help / CronJobs

Help.CronJobs History

Hide minor edits - Show changes to output

Changed lines 47-53 from:
to:
If you'd like to disable the e-mail that is sent when the cron job fails you can send stderr (2) to stdout (1) like this:

->00 6 * * 3 /home/netid/path/to/program/program.pl >>/dev/null 2>&1

->so now both messages from the program and errors about the cron job will be ignored. Only do this once you're sure things are running as you need them to.
Added lines 1-73:
!A Few Words about Cron Jobs


!!Create a .forward file:

If you are planning to set up a cron job on your account on itp.nyu.edu, you should be aware that if there is a problem with the cron job or there are any messages from the cron job, an e-mail will be sent to your account on the itp server.

Before setting up a cron job you should create a .forward file in the top level of you home directory (note the the name of the file starts with a dot). Inside the .forward file you place one line that has your e-mail address. You can run these two commands in an ssh terminal window:

->echo netid@nyu.edu >.forward\\
chmod 600 .forward

Replace netid@nyu.edu with whichever e-mail address you want to forward the mail to. This way any e-mail generated by your cron job will get to you.

If you have already set up a cron job on your account and have not set up the .forward file, please do so now. You should also check for e-mail by opening an ssh terminal window and using the linux "mail" line command or talk to Nancy about deleting any mail that has already been generated.


!!Minimize Output from a Cron Job:

If the job is run often and generates an e-mail every minute or hour, that can take up a lot of your inbox, so before having a program run every minute, run a couple of tests having it run a couple of times only and then check if any e-mail was generated.

If you are running a perl program, you might want to check the first line of the program if it says:

->#!/usr/bin/perl -w

Remove the -w that means print out all warnings.


Also if you have any print statements to standard out, those will be sent to you in an e-mai unless you send output from the program itself to a file, by changing the crontab line from

->00 6 * * 3 /home/netid/path/to/program.pl

->to something like:

->00 6 * * 3 /home/netid/path/to/program.pl >/home/netid/path/cron.out

->This will put any output into a file called cron.out, which you can check to see what the results were the last time the program ran. This file will get written over each time the job runs.

->or to this:

->00 6 * * 3 /home/netid/path/to/program/program.pl >/dev/null

->This says send output to this dummy place (aka ignore it)

Alternatively, once you know the program is working you may want to comment out the print statements.


!!Start the Cron Job a few seconds later:

Please, make sure you really need a program to run every minute before setting up a crontab to do so and if you're part of a class where everyone is running crontabs, please spread your crons out by having them run at say 15 seconds, 20 seconds, 30 seconds . . . after the minute. You do this by adding "/bin/sleep nn;" before the command you want to execute, where nn is the number of seconds to "sleep" before executing the next command.

->For example:

-->*/5 * * * * /bin/sleep 45;/home/netid/path/to/program/program.pl >/dev/null

-->Will run every 5 minutes at 45 seconds after the minute.



!!Secure location of program:

Cron jobs are run from the line command and genrally not run from within a web browser; therefore, the program should not be placed inside the public_html folder where it could be accidently accessed through a web browser. For security purposes, it is best to put your program in a folder at the top level of your account such as:

->/home/netid/bin\\
or\\
/home/netid/classname





If you have any questions or suggestions for this page, send an e-mail to [[mailto:itp.helpdesk@nyu.edu | itp.helpdesk@nyu.edu]]
Page last modified on March 20, 2007, at 04:16 PM