View Full Version : cron job
3-10-02, 02:12 PM
Ive been trying for weeks to get my cron to work, and no luck. Ive read the other threads and nothing seems to work. I placed a file named crontab in the etc directory, simple permission, blank line after the entry, with the following call:
30 10 * * * /www/n/nwtucson/etc/script.cgi
Any help would be great!
Hope you dont mind my guessing while you wait for an answer from those who really know.
It looks like you are calling script.cgi to run. It would appear from that path that you have it in the "etc" folder. To the best of my knowledge, a cgi script will only run from the cgi folder. Perhaps that is the problem? I would have guessed that line should look more like:
30 10 * * * /www/n/nwtucson/cgi-bin/script.cgi
Hope this stab in the dark helped.
3-10-02, 06:17 PM
i have tried cgi-bin, htdocs, and etc, none seem to work ...
First, I still think your cgi script should be in your cgi-bin
Next, did you leave a blank line after your one line command? You need to do that or the Cron job will not run.
Did you name the file "crontab"? It must be lower case and have no file extension. Dont put the quotation marks.
Did you upload it to your etc directory using ASCII?
I know this is basic stuff, but it's the only help I can give. Hope it does help
3-10-02, 11:27 PM
Add redirection to your cron job entry. Right now any output that comes from your cron job is going in the bit bucket. Running from the /etc directory is fine as long as the script is chmoded to be executeable. For redirection I recommend something like this:
30 10 * * * /www/n/nwtucson/etc/script.cgi >>/www/n/nwtucson/logs/script.log 2>>/www/n/nwtucson/logs/script.err
The 2> redirection will capture standard error which will let you see any error messages that are occurring when cron tries to run your programs. The double redirection will allow it to extend your logs so you can see the results from each time it runs in case you don't check on it each time it runs.
You also need to understand that a cron job needs to be written differently than a cgi script. I wouldn't even use .cgi as the extension since it is running from cron, not from a webserver. If this distinction is not clear then that may be were some of your problems in getting this to run are coming from. Not trying to be insulting or critical, but not all programs are cgi programs.
3-15-02, 06:01 PM
You also need to understand that a cron job needs to be written differently than a cgi script.
How so? I was unaware of this so could you please elobrate on what exactly is different and needs to be changed?
Thank you again
3-15-02, 11:20 PM
When a program runs it needs to have a certain environment in which it has access to those things it needs. For instance, the standard perl modules that can be included are found by following a path which is often defined in an environment variable. There is a "current directory" which might need to be considered when referencing a file. Are your logs being written into the current directory or another? From a cgi-bin directory you might need to use a path such as "../htdocs" to reference another directory. However, if your current directory were your powweb home directory "/www/i/initialdir" then a reference to "../htdocs" might result in an error since it might be trying to reference the "/www/i/htdocs" directory.
When a cgi script is running it expects to be initiated by a web server in response to a request from a browser. As such there might be parameters which could be accessed differently based on whether the "post" method or the "get" method were used. Furthermore, output from the program needs appropriate html header, body, etc. so that that output can be sent by the web server back to the browser and be interpreted and displayed as proper html code. The web server also sets environment variables for the cgi script which indicate the OS of the browser's computer, the url invoking the request for service, and so forth. A cron job would not have any of these environment variables set.
When a non-cgi program, such as a cron job, is run it has no expectation to find any environment created by a web server. Thus, if you want to pass parameters as command line parameters then you need to include them yourself when you specify the job in the crontab file. If you want the program to read from a file or write to a file then the program must either be hard coded for that file or be passed parameters or a configuration file or something to tell it any options you wish to specify. It is unlikely that you would want a program which runs as a cron job to produce html code as standard output (though that is also possible, consider a cron job that analyzed a log file and generated an html file which showed summary data about that logged data, though you would need to specify that this output should be redirected to a disk file or else the html data will be sent to /dev/null since there is no web server waiting to pass the program's standard output back to a browser).
As another example of a different kind of program, think of a VB program written to be run on your PC. If this program were written such that it opened a window, displayed a button and then waited until you clicked on the button to execute the work of the program then this program would be useless as a cgi program or as a cron job. The gui interface doesn't exist for the cgi program or cron job so there isn't a way for the button to be pushed and the program will either die because it cannot access a proper gui interface or it will hang forever because no one can click on the button.
These are the type of things I mean when I say that not all programs are cgi programs and there might need to be different considerations for cron jobs or cgi programs.
Does that help?
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.