Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Last active January 30, 2019 02:02
Show Gist options
  • Save harrisonmalone/5fc1b01f5af378ff9c593e58b5ec9de0 to your computer and use it in GitHub Desktop.
Save harrisonmalone/5fc1b01f5af378ff9c593e58b5ec9de0 to your computer and use it in GitHub Desktop.
cronjobs work with ruby and js
def hello
# File.open(Random.rand.to_s + '.txt', "w+") { |f| f.write("write your stuff here") }
open('hello.txt', 'a') { |f| f.puts "Hello, world!" }
end
hello
# same process to run the cronjob as in test.js
# use which ruby to find where ruby is installed
var fs = require('fs');
fs.writeFile(Math.random() + '.txt', "Hey there!", function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
// cronjob
// */1 * * * * cd ~/Desktop/public && /usr/local/bin/node test.js
// runs every minute with */1, need to cd into that directory as all cronjobs run from home by default, then node needed the full path to work correctly as well, then run the file as normal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment