I've a script that runs fine when I ssh to my ubuntu EC2 instance and run it (as the user
I want this to happen when the server boots, so I added it to cron as:
@reboot sleep 10 && /home/ubuntu/start.sh
However when cron runs it, the
PATH is not the same and some commands fail because binaries are not loaded:
$ echo $PATH /home/ubuntu/.nvm/versions/node/v4.2.6/bin:/home/ubuntu/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin # in start.sh echo "path $PATH" >> start.logs # will log 'path /usr/bin:/bin'
I've tried to add
source /home/ubuntu/.bashrc in my
start.sh script since I believe that's where the
PATH is built, at least partially, but that doesn't seem to change much:
# in start.sh source /home/ubuntu/.bashrc echo "path $PATH" >> start.logs # will still log 'path /usr/bin:/bin'
I've also checked that Cron runs as
ubuntu and not
root, which seems to be the case since I edited the cron jobs being logged in as
Is there an easy way to get cron run in the same environment I get after login to my server by ssh?