Crontab issue for running script to start server

I am on ec2 instance ubuntu server and playing around with bash scripting. I have a very simple script which runs when the server reboots.

 cd /home/ubuntu/d/web

echo  "Start Phoenix server"** > server.log

whoami > server.log

date >> server.log

pwd >> server.log

source .env

mix phx.server >> server.log 2>&1

I got this error after the server reboots.

/home/ubuntu/ 7: mix: not found

It works fine until the mix phx.server line.

I have this line in crontab -e file

 @reboot /home/ubuntu/

If I run the script like this, it works fine.


What I don’t understand is why I am getting mix not found error.

I am using asdf for version control.

Any hint will be much appreciated.


Cron do not set PATH so it doesn’t know where mix is.

However I would suggest you to use releases for production deployments instead of running mix phx.server and to start such release via systemd (or other system supervisor of your choice).