Adding import from crontab

v0.1.8
Michael 2016-08-04 17:49:22 -04:00 committed by alse
parent 78f133a075
commit 285bcd1f25
4 changed files with 40 additions and 9 deletions

1
app.js
View File

@ -34,6 +34,7 @@ app.set('port', (process.env.PORT || 8000));
app.get(routes.root, function(req, res) {
// get all the crontabs
crontab.reload_db();
crontab.crontabs( function(docs){
res.render('index', {
routes : JSON.stringify(routes),

View File

@ -133,16 +133,35 @@ exports.get_env = function(){
exports.import_crontab = function(){
exec("crontab -l", function(error, stdout, stderr){
var lines = stdout.split("\n");
lines.forEach(function(line){
/*
trim the spaces at edges
split the line based of space and tab
remove empty splits
If the first character is @
*/
//if(line.indexOf("@")
var namePrefix = new Date().getTime();
lines.forEach(function(line, index){
var regex = /^((\@[a-zA-Z]+\s)|(([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s))/;
var command = line.replace(regex, '').trim();
var schedule = line.replace(command, '').trim();
if(command && schedule){
var name = namePrefix + '_' + index;
db.crontabs.findOne({ command: command, schedule: schedule }, function(err, doc) {
if(err) {
throw err;
}
if(!doc){
exports.create_new(name, command, null, null, schedule, null);
}
else{
doc.command = command;
doc.schedule = schedule;
exports.update(doc);
}
});
}
})
console.log(stdout);
//console.log(stdout);
});
}

View File

@ -53,6 +53,16 @@ function setCrontab(){
});
}
function getCrontab(){
messageBox("<p> Do you want to get the crontab file? </p>", "Confirm crontab retrieval", null, null, function(){
$.get(routes.import_crontab, { "env_vars": $("#env_vars").val() }, function(){
// TODO show only if success
infoMessageBox("Successfuly got the crontab file!","Information");
location.reload();
});
});
}
function editJob(_id){
var job = null;
crontabs.forEach(function(crontab){

View File

@ -35,6 +35,7 @@
<a class="btn btn-warning" onclick="import_db()"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import</a>
<a class="btn btn-warning" href="<%= JSON.parse(routes).export %>"><span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span> Export</a>
<!--<a class="btn btn-info" onclick="import_crontab()"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import from crontab</a>-->
<a class="btn btn-success" onclick="getCrontab();"><span class="glyphicon glyphicon-save" aria-hidden="true"></span> Get from crontab</a>
<a class="btn btn-success" onclick="setCrontab();"><span class="glyphicon glyphicon-save" aria-hidden="true"></span> Save to crontab</a>
<br/>
<br/>