Additional Perl cron operational notes

Perl Script Test in the shell via SSH
In order to test your uploaded PERL script you can use ssh to log into the shell if you have enabled shell access. After logging in, Go to the directory where your script is located, and type as thus at the prompt: perl yourscript.pl Where yourscript.pl is the file name of your script (you may have named your file differently). Nothing will happen if you only type in yourscript.pl other than an error message saying : COMMAND NOT FOUND

Contents of the crontab file
As mentioned in the main page about crontab operation you can not use only the command. You must use a full path because Dreamhost does not have an environment set up: /5 * * * * /usr/local/bin/perl       /home/YourUserName/YourDomain.com/YourScript.pl Notice the perl command with its path and the script with its path. The path of YourDomain is due to the directory structure on the server. You can see this structure by logging on using TelNet and moving up and down the directory structure to view it. Its helpful to do so in order to have a more complete mental picture of your server. Time interval specification is for testing purposes only. You can use a script to email yourself every 5 minutes for test purposes.

PATH OK
$ PATH=/usr/bin:/bin which perl /usr/bin/perl shows the PATH issue might be solved, as of 18:32, 6 March 2008 (PST).

Where to put the crontab file
The statement in the main crontab page appears to imply that the file goes in the domain directory: /home/UserName/YourDomain.com/mytextfile.txt
 * If you create a crontab file and upload, what directory should the file be put in ?


 * Use your FTP client to do an ASCII transfer. ( must be ASCII )
 * Put the file where it makes sense to you. I use the root directory of my user name. Appears like I can only have one crontab file per UserName. Thus all domains under this UserName will use the same crontab file.  In the following step you "install" the file to let the cron process know what file you want used.

Install the crontab file
Go to the directory with your cron file and type: crontab cronfile.ctb   ( my file was cron.ctb, you might have a different name and extension ) Then verify your cron file by typing: crontab -l Your cron file should be listed out and agree with what you think it should be.

Testing and Problems
Testing went this way for me:


 * 1-upload and chmod the script I want to run periodically using crontab. This script simply sent me an email every 5 minutes. It also automatically sends an email to a directory Maildir/new.


 * 2-Test the script to make sure its all correct using a browser interface


 * 3-Test using TelNet to run the script. I found that though the script would run in a browser interface that for some reason TelNet was more picky. I had to massage my script because it could not find a library function I wanted to use.

Can't open perl script "/home/UserName/YourDomain.com/cron.cgi": No such file or directory See: Cron-Email-Error-Message. In order to see this for yourself you will need to FTP it from your Maildir/new directory.
 * 4-upload the crontab file. Ran into trouble here. The email to the Maildir/new directory on server host said:

After checking everything things seemed to be in correct condition. The only thing left was a problem with a stray character in the crontab file. My multi-edit editor must have added an extra character. I found that the line in the crontab ended with a character that does not display ( Hex = 0D ). Although this standard in the line ending in Windows ( Windows Line Ending = 0A0D ) it is invisible in a text editor on UNIX machine ( Except vi/vim, and maybe a few others ) and adds a character to the end of the command, and although it looked like /dev/null was the end of the line it was actually /dev/null\0x0D. I've corrected this issue and used the correct line ending ( Hex = 0A ) for unix machines.

ALTERNATE METHOD: Easy New WebPanel CRON Setup
Just received the April newsletter email, and of all things, it mentions CRON !

Look under the GOODIES tab and click on CRON. It allows you to set up without all the potential snags. Dreamhost must have gotten their fill of cron support questions !!!

Email Notification to Your Disk Directory: Maildir/new
Unless you specify no email notification of the crontab job running you an email file will be recorded into your UserName/Maildir/new directory on the dreamhost server. During testing this is a good feature as your script path or file may be in error as was mine as detailed above. The error message contained in this email file was very helpful to show that while the crontab file was being executed the script file was not being found.

Once you are done testing your crontab you should probably shut off the email file output. Otherwise these files will pile up endlessly. Look here for information on how to do this: Cron