0

A newly created crontab job is failing because the program can't read a .json file containing credentials in the same directory. Both files are contained in a /home/deploy/app/ folder. Crontab executes /home/deploy/app/app which needs to read home/deploy/app/config.json to execute. The program runs fine a the deploy user, but fails when run by crontab.

I am sure this is the reason the program is failing since I directed the crontab job to log its output, and I can see that the program is unable to read the config.json file. The app has the following permissions -rwxr-xr-x 1 deploy deploy and the config.json has -rw-rw-r-- 1 deploy deploy.

The crontab entry is:

10 0,6,9,12,15,18 * * * /home/deploy/gocode/bin/BuoyBot > /home/deploy/buoybot.log 2>&1

The cron log records the error from the app, which indicates is it unable to load the config.json file stored in the same folder as the app.

error loading config.json: invalid argument

This error does not occur when the program is run manually from within the /home/deploy/gocode/bin/ folder.

UPDATE: The solution, as suggested below, was to reference the full path of the config.json file within the app (/home/user/app/config.json), rather than a reference to the local directory (config.json).

surfearth
  • 103

2 Answers2

2

Without seeing the code my guess is that you are not providing the full path to your data file when you attempt to open it.

user9517
  • 117,122
-1

Can you try launching the cron as the user deploy as follows:

10 0,6,9,12,15,18 * * * deploy /home/deploy/gocode/bin/BuoyBot > /home/deploy/buoybot.log 2>&1

Alternatively you can try as follows also:

10 0,6,9,12,15,18 * * * deploy cd /home/deploy/gocode/bin/ &&  ./BuoyBot > /home/deploy/buoybot.log 2>&1

Hope it helps.