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:
chmod 600 .forward
Replace email@example.com 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:
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
Alternatively, once you know the program is working you may want to comment out the print statements.
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:
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.
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:
If you have any questions or suggestions for this page, send an e-mail to firstname.lastname@example.org