0

Possible Duplicate:
shell script doesn't run correctly in cron

I want to call a shell script I wrote from a cron. The shell script uses the program Linkchecker. If I run the shell script from the terminal it works just fine. However, when cron runs I get the following errors:

File "/Users/keith/etc/cron/linkchecker", line 40, in from linkcheck.director import console, check_urls, get_aggregate
File "/opt/local/lib/python2.5/site-packages/linkcheck/director/init.py", line 25, in from . import aggregator, console File "/opt/local/lib/python2.5/site-packages/linkcheck/director/aggregator.py", line 25, in from . import logger, status, checker, cleanup File "/opt/local/lib/python2.5/site-packages/linkcheck/director/status.py", line 20, in from . import task File "/opt/local/lib/python2.5/site-packages/linkcheck/director/task.py", line 20, in from . import console File "/opt/local/lib/python2.5/site-packages/linkcheck/director/console.py", line 27, in stderr = codecs.getwriter(i18n.default_encoding)(sys.stderr, errors="ignore") File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/codecs.py", line 930, in getwriter return lookup(encoding).streamwriter LookupError: unknown encoding: Traceback (most recent call last):
File "/Users/keith/etc/cron/linkchecker", line 40, in from linkcheck.director import console, check_urls, get_aggregate
File "/opt/local/lib/python2.5/site-packages/linkcheck/director/init.py", line 25, in from . import aggregator, console File "/opt/local/lib/python2.5/site-packages/linkcheck/director/aggregator.py", line 25, in from . import logger, status, checker, cleanup File "/opt/local/lib/python2.5/site-packages/linkcheck/director/status.py", line 20, in from . import task File "/opt/local/lib/python2.5/site-packages/linkcheck/director/task.py", line 20, in from . import console File "/opt/local/lib/python2.5/site-packages/linkcheck/director/console.py", line 27, in stderr = codecs.getwriter(i18n.default_encoding)(sys.stderr, errors="ignore") File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/codecs.py", line 930, in getwriter return lookup(encoding).streamwriter LookupError: unknown encoding: Traceback (most recent call last):
File "/Users/keith/etc/cron/linkchecker", line 40, in from linkcheck.director import console, check_urls, get_aggregate
File "/opt/local/lib/python2.5/site-packages/linkcheck/director/init.py", line 25, in from . import aggregator, console File "/opt/local/lib/python2.5/site-packages/linkcheck/director/aggregator.py", line 25, in from . import logger, status, checker, cleanup File "/opt/local/lib/python2.5/site-packages/linkcheck/director/status.py", line 20, in from . import task File "/opt/local/lib/python2.5/site-packages/linkcheck/director/task.py", line 20, in from . import console File "/opt/local/lib/python2.5/site-packages/linkcheck/director/console.py", line 27, in stderr = codecs.getwriter(i18n.default_encoding)(sys.stderr, errors="ignore") File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/codecs.py", line 930, in getwriter return lookup(encoding).streamwriter LookupError: unknown encoding: Traceback (most recent call last):
File "/Users/keith/etc/cron/linkchecker", line 40, in from linkcheck.director import console, check_urls, get_aggregate
File "/opt/local/lib/python2.5/site-packages/linkcheck/director/init.py", line 25, in from . import aggregator, console File "/opt/local/lib/python2.5/site-packages/linkcheck/director/aggregator.py", line 25, in from . import logger, status, checker, cleanup File "/opt/local/lib/python2.5/site-packages/linkcheck/director/status.py", line 20, in from . import task File "/opt/local/lib/python2.5/site-packages/linkcheck/director/task.py", line 20, in from . import console File "/opt/local/lib/python2.5/site-packages/linkcheck/director/console.py", line 27, in stderr = codecs.getwriter(i18n.default_encoding)(sys.stderr, errors="ignore") File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/codecs.py", line 930, in getwriter return lookup(encoding).streamwriter LookupError: unknown encoding: Traceback (most recent call last):
File "/Users/keith/etc/cron/linkchecker", line 40, in from linkcheck.director import console, check_urls, get_aggregate
File "/opt/local/lib/python2.5/site-packages/linkcheck/director/init.py", line 25, in from . import aggregator, console File "/opt/local/lib/python2.5/site-packages/linkcheck/director/aggregator.py", line 25, in from . import logger, status, checker, cleanup File "/opt/local/lib/python2.5/site-packages/linkcheck/director/status.py", line 20, in from . import task File "/opt/local/lib/python2.5/site-packages/linkcheck/director/task.py", line 20, in from . import console File "/opt/local/lib/python2.5/site-packages/linkcheck/director/console.py", line 27, in stderr = codecs.getwriter(i18n.default_encoding)(sys.stderr, errors="ignore") File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/codecs.py", line 930, in getwriter return lookup(encoding).streamwriter LookupError: unknown encoding: Traceback (most recent call last):
File "/Users/keith/etc/cron/linkchecker", line 40, in from linkcheck.director import console, check_urls, get_aggregate
File "/opt/local/lib/python2.5/site-packages/linkcheck/director/init.py", line 25, in from . import aggregator, console File "/opt/local/lib/python2.5/site-packages/linkcheck/director/aggregator.py", line 25, in from . import logger, status, checker, cleanup File "/opt/local/lib/python2.5/site-packages/linkcheck/director/status.py", line 20, in from . import task File "/opt/local/lib/python2.5/site-packages/linkcheck/director/task.py", line 20, in from . import console File "/opt/local/lib/python2.5/site-packages/linkcheck/director/console.py", line 27, in stderr = codecs.getwriter(i18n.default_encoding)(sys.stderr, errors="ignore") File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/codecs.py", line 930, in getwriter return lookup(encoding).streamwriter LookupError: unknown encoding:

I have chmod 777 the linkchecker file. I have moved the linkchecker file to my current home directory. I added the cron by saying

crontab -e

I put in

38       12      *       *       5      /Users/keith/etc/cron/linkchecker.sh

The first line of my shell script is #!/bin/sh

So the only thing I can think of is I'm missing some environment variables when cron runs. When I add env at the top of my script and compare the variables from when cron runs versus from the terminal there is a difference. According to https://stackoverflow.com/questions/1694942/environment-variable-used-in-shell-script-appear-blank-in-log-file-when-run-by-cr I can add . /etc/profile and that should put in the correct environment variables. This does not appear to be sucking in the variables because the variables are still the same when I use env.

I am on a Mac if that makes any difference. Also I pasted in the working variables at the top of my script that worked when I run from terminal and cron still didn't work.

1
  • Based on the "unknown encoding" error. Try setting the LANG and LC_ALL in your crontab to the same value you use in the terminal. You can use the command locale to view this values. Jul 8, 2011 at 21:45

1 Answer 1

1

Try this

38 12 * * 5 /bin/bash -l -c /Users/keith/etc/cron/linkchecker.sh

The -l option will get a login environment for executing the script.