TheElbowClaps
TheElbowClaps

Reputation: 59

Heroku CLI command does not work when executed by cron

I'm running a cron job which executes a shell script. What the shell script does is execute a few heroku-cli commands, for example:

#crontab
* * * * * /path-to-script/my-script.sh > log
#!/bin/bash
token=$(heroku config:get MY_TOKEN --app my-heroku-app)
echo $token

From the code snippet above, I expected the token to be retrieved from the heroku command and saved to the log. But it seems that the command couldn't even be executed when I checked my log file. When I execute the shell script without using cron, everything worked just fine.

Upvotes: 0

Views: 231

Answers (1)

TheElbowClaps
TheElbowClaps

Reputation: 59

Oh nvm i figured it out. I have to execute the command as the user who has heroku-cli. So basically:

sudo -u username heroku config:get ...

Upvotes: 2

Related Questions