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).

  • 1
    Please show us the output from the log file. – user9517 Nov 15 '15 at 18:56
  • Added additional information above. – surfearth Nov 15 '15 at 20:18
  • Work your way through the duplicate above. It will almost certainly help you solve your problem. If i does not it will help you gather information that will help us help you. That information should be edited into your question. – user9517 Nov 15 '15 at 20:24
  • I carefully read the above mentioned link, but it does not address the issue. Cron is successfully executing the program, however when it runs the program is not capable of accessing a supporting file in the same directory. More precisely, the command /home/deploy/gocode/bin/BuoyBot runs, but the BuoyBot program is unable to access the credentials loaded in /home/deploy/gocode/bin/config.json`. – surfearth Nov 16 '15 at 0:00
  • 1
    The app is trying to access to config.json or /full/path/config.json? – Jose Raul Barreras Nov 16 '15 at 3:55

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.

| improve this answer | |
  • 1
    UPDATE: The solution, as suggested by lain, 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 Nov 20 '15 at 16:34

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.

| improve this answer | |
  • Those are not valid user crontab entries, which is the kind of crontab the OP has indicated (s)he's using. – MadHatter Nov 16 '15 at 8:06
  • This would only work in the /etc/crontab (or similar) file which requires a user name. KIt may not be accessible to the OP. It doesn't work in a user crontab. – user9517 Nov 16 '15 at 8:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.