0

I'm trying to set up a node script to run as a cron job on Joyent. I can run arbitrary commands but node scripts to seem to execute. As an example:

# cron
# call a script every minute
# being specific about the location of node and the script to run 
* * * * * /home/node/local/nodejs/bin/node /full/path/to/some-script.js

// node script at /full/path/to/some-script.js
var fs = require('fs');
fs.writeFile('/home/node/node-service/some-script.log', new Date.toString(), 'utf8');

What I expect to see after one minute is a file at /home/node/node-service/some-script.log with content like Mon Jan 21 2013 15:19:11 GMT-0600 but I see nothing. This is still the case even if the script is set to full read, write and execute permissions for all users and whether the crontab is set for the root or node users.

What am I missing?

Thanks

smabbott
  • 792
  • 1
  • 7
  • 13

2 Answers2

0

The fourth optional argument to writeFile is a callback to fire when the file system is done writing the file. You can use it to determine the error that is happening, as it's only argument is an error. Refer to the docs here.

Tj Krusinski
  • 116
  • 3
  • When I run the script manually it runs as expected. Using `writeFile` the error object is null. Tailing the cron log I see `> CMD: /home/node/local/nodejs/bin/node /home/node/node-service/activities-sweeper.js > node 15781 c Tue Jan 22 17:34:00 2013 < root 15780 c Tue Jan 22 17:34:00 2013 rc=1 /etc/mail/sendmail.cf: line 0: cannot open: No such file or directory < node 15781 c Tue Jan 22 17:34:00 2013` `No such file or directory` sounds like node or my script isn't being found but I know they are there. Could it be a permissions issue? – smabbott Jan 22 '13 at 17:47
  • I'm not sure if it's a permission issue, I'd imagine the OS would say you did not have permission not that the dir can't be found. Maybe try and run it under sudo to see what happens? – Tj Krusinski Jan 23 '13 at 14:44
0

It appears to be working now. I'm not sure what I changed that got it working. It may have been a permissions issue.

smabbott
  • 792
  • 1
  • 7
  • 13