"getpwnam() failed" in /bin/sh only when called from cron "getpwnam() failed" in /bin/sh only when called from cron shell shell

"getpwnam() failed" in /bin/sh only when called from cron


It surprises me that nobody has the correct answer to this. Today i faced exactly the same problem and google didn't help.

After 2 hours i found that when placing a file in /etc/cron.d the schedule line has to contain an extra option.....

I allways use this for my crontab -e

# Minute   Hour Day of Month     Month          Day of Week     Command    # (0-59)  (0-23)   (1-31)  (1-12 or Jan-Dec)  (0-6 or Sun-Sat)  /my/fancy/script.sh            

So it contains 6 items.

When placing this in a file inside /etc/cron.d the cron needs an extra option, being the user to run your fancy/script.

# Minute   Hour Day of Month     Month          Day of Week     Who   Command    # (0-59)  (0-23)   (1-31)  (1-12 or Jan-Dec)  (0-6 or Sun-Sat)  root  /my/fancy/script.sh            

This is documented in man crontab(5). For example https://linux.die.net/man/5/crontab . It says:

Jobs in /etc/cron.d/

The jobs in cron.d are system jobs, which are used usually for more than one user. That's the reason why is name of the user needed. MAILTO on the first line is optional.


The sixth position is reserved for username running the job. You specified a user called sh which is most probably not present on the machine.


simple answeron your crontab you need to specify the USER to run the command

example to run as ROOT is:-

0,10,20,30,40,50 * * * * root /path_to_script/script_name

or to run as user FRED

0,10,20,30,40,50 * * * * fred /path_to_script/script_name

default with no USER specified is to run as user CRON and that user would not have permissions to execute the script