dachev / node-crontab

A module for creating, reading, updating, and deleting system cron jobs
189 stars 35 forks source link

Add support for environment variables #29

Closed gavinhungry closed 4 years ago

gavinhungry commented 6 years ago

Adds support (with test) for reading/writing environment variables within crontabs. Also resets variables when reset is called.

crontab:

FOO=bar
LIBS_DIR=/some/lib/dir

*/10 * * * * /usr/bin/something
require('crontab').load((err, crontab) => {
  console.log(crontab.env);
  // { FOO: 'bar', LIBS_DIR: '/some/lib/dir' }
});
delete crontab.env.FOO;
crontab.env.LIBS_DIR='/some/other/lib/dir'
crontab.env.BAR = 'okay';

console.log(crontab.render());
LIBS_DIR=/some/other/lib/dir
BAR=okay

*/10 * * * * /usr/bin/something
dachev commented 6 years ago

@gavinhungry Sorry for taking so long. This looks great! I'll merge it in the upcoming weeks.

dachev commented 4 years ago

@gavinhungry I ended up implementing this in a slightly different way and released 1.3.0. Please take a look at the updated README. Thank you for the PR and sorry for taking so long. This was a great contribution!