Running cronjob as root user in aws. ruby v 3.0, rails v 7.0.2.4.
The file that is created from running aws ebextension.
files:
#The things to run inside cron task
“/usr/local/bin/tasks.sh”:
mode: “000755”
owner: root
group: root
content: |
#!/bin/bash
if [ “$RAILS_ENV” = “production” ]
then
cd /var/app/current
bundle exec bin/rails runner -e production lib/device_proc.rb >> /tmp/log1.log 2>&1
elif [ “$RAILS_ENV” = “staging” ]
then
cd /var/app/current
bundle exec bin/rails runner -e staging lib/device_proc.rb >> /tmp/log2.log 2>&1
fi
#Run cron task every 5 minutes
"/etc/cron.d/tk_cron":
mode: "000644""
owner: root
group: root
content: |
0,5,10,15,20,25,30,35,40,45,50,55 * * * * root /usr/local/bin/tasks.sh
I am testing crontab in staging environment. I checked the created log file and it gives error
/usr/local/bin/tasks.sh: line 9: bundle: command not found
But if I run the command from aws session manager console, as root user, the command works. It is just that running from cronjob is throwing errors, despite that both are run as root user.
I tried running the bundle
from my ruby installation path, /var/app/current/vendor/bundle/ruby/3.0.0/bin/bundle exec
as been discussed in this question, but to no avail.