Originally Posted by nathanpayne
Do you know how I find out what user the crontab will be running the script as?
You could use the id
command in the script.
But the issue may not be with the user; it may be with the environment set up by cron. cron sets up an enviroment which is restricted when compared with the logon environment. The usual gotcha is that PATH is basic. The PATH workaround is either for the script to set the PATH that it needs (always good defensive programming practice) or to give full paths to all commands used, for example /bin/wc
(assuming that is the full path of wc
on the system).
If that does not fix the problem you can try changing the shebang line to make the shell set up the same environment as if it was a logon shell. For bash:
That's a letter l, for logon.
If that works it is not robust to leave it that way; if anybody changes the bash initialisation files so they prompt for user input the script will fail when run by cron. If that works, it is a good test to show that something of the logon initialisation process is required and the analysis of what can begin.