Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a zsh script that I would like to run via anacron every week.

It runs fine from an interactive bash shell, but when run by anacron, I am getting command not found errors and it looks like it is ignoring the shebang line.

The actual /etc/cron.weekly/ script is:


[ -x SCRIPT ] || exit 1


And the top line of the actual script is #!/bin/zsh

How can I get anacron to honor the shebang? Would changing NORMAL_USER's login shell to zsh accomplish this?

share|improve this question
up vote 2 down vote accepted

Why it doesn't Work:
The reason that it doesn't work is that su requires that you run the command from a terminal, and cron does not provide a terminal.

Simple way to do it is using Vixie Cron:
If you didn't mind using Vixie Cron I think the simplest thing to do would be to put the script in for that user by running the following as that user:

crontab -e

Then use 0 0 * * 0 as the time.

If you want to use Anacron as a User:
Anacron is helpful if you want to make sure the job doesn't get missed if the machine was off. To run as different user, specify a different anacron tab file and spool dir, put the following in the system cron to run as the specified user, anacron -t /home/foo/etc/anacrontab -S /home/foo/var/spool/ and then edit that tab file to run the script.

There is also a mini-howto, but this looks more complicated.

You will have to test these though to verify. Lastly, remember this for future testing run-parts --test /etc/cron.weekly

share|improve this answer

The shebang should take care of it. The first thing I look at when scripts don't run correctly under cron is environment variables such as $PATH. The $PATH for cron is much simpler than that of a user. You can set a $PATH in the cron script.

You can also hard-code the full path to all executables in your script.

If zsh is not at /bin/zsh you should get an invalid interpreter message, but you said it's running fine from a Bash prompt, so I doubt that's the problem.

share|improve this answer

Changing the user's login shell to zsh makes this work. I had been wanting to try out zsh as my login shell for awhile anyway. Nothing like necessity to give you a push to do something.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.