Question:
I have a script that I can load via my web browser, but not via the command line. How can I run this script in a cron job?
Answer:
Yes. There is a text-only UNIX web browser called Lynx that can be used with cron to automatically run scripts that work in web browsers.
Detail:
On occasion you may find yourself using a script that does not work properly when run outside of a web environment. For example, running the script from a shell prompt might give you a segmentation fault or another system error. However, if you load the script from your web browser, it may work fine.
Fortunately, there is a way to run a UNIX web browser from cron, so that you can schedule cron to load the URL, thus running the script.
Solution:
You can use the UNIX text-based browser, lynx, to run scripts that can only run from a web page. The cron job would look like this:
lynx -dump http://domain.com/cgi-bin/scriptname > /dev/null
This version runs the binary without any output. If you want to see the output, use:
lynx -dump http://domain.com/cgi-bin/scriptname | mail -s “’This is the output from the script scriptname.’” user@domain.com
This will mail you the output.
Make sure to substitute domain.com for the domain name in question; scriptname should be the actual script's name; and 'user@domain.com' should be replaced with the destination address for the script.
Comments:
The Lynx users guide can be found here: