(Using an Ubuntu EC2 on AWS)
I've a script, /home/ubuntu/start.sh
. If I run it as ubuntu
, it runs well. I need it to be run at launch, so I put it in /etc/rc.local
. This will then be run as root on reboot, and this fails. I'm able to reproduce the failure by:
# I'm ubuntu
$ whoami
ubuntu
$ sudo su
# i'm now root
$ whoami
root
$ ./start.sh
./start.sh: line 9: npm: command not found
$ su -c ./start.sh - ubuntu
./start.sh: line 9: npm: command not found
So it looks like:
- root doesn't know about
npm
(installed byubuntu
under/home/ubuntu/.nvm/versions/node/v4.2.6/bin/npm
so that makes sense) su -c ./start.sh - ubuntu
doesn't exactly run the script as ubuntu
How can I run this script exactly as if I was logged in as ubuntu
?
sudo -E ./start.sh
Regarding/etc/rc.local
. I would run it as user ubuntu:sudo -i -u ubuntu /home/ubuntu/start.sh
– rudimeier Nov 4 '16 at 23:22