Created
December 20, 2016 20:11
-
-
Save bogdanpetru/ec12524c5a52f72929770fba93a978af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var exec = require('child_process').exec; | |
var command1 = `ls -l` | |
var command2 = `ls` | |
var command3 = `cd ..` | |
var intervalCommand1 = ( // 10 ore | |
1000 * | |
60 * // sec | |
60 * // min | |
10 // ore | |
) // e in milisecunde | |
var intervalCommand2 = ( // 2 min | |
1000 * 3 | |
60 * // sec | |
1 // min | |
) | |
var intervalCommand3 = ( // 1 min | |
1000 * | |
60 * // sec | |
1 // min | |
) | |
var process1, process2, process3; | |
function command1_func() { | |
// kill previous processes | |
if (process1 && process1.kill) { | |
process1.kill() | |
} | |
if (process2 && process2.kill) { | |
process2.kill() | |
} | |
if (process3 && process3.kill) { | |
process3.kill() | |
} | |
process1 = exec(command1, function(error, stdout, stderr) { | |
if (error) { | |
console.log('error - comanda generala', error) | |
} | |
console.log('stdout - comanda generala', stdout) | |
command2_func() | |
}) | |
} | |
function command2_func() { | |
// dupa ce se executa comanda 1 se executa: | |
// setTimeout executa odata dupa un interval de timp | |
setTimeout(function() { | |
process2 = exec(command2, function(error, stdout, stderr) { | |
if (error) { | |
console.log('error - comanda 2', error) | |
} | |
console.log('stdout - comanda 2', stdout) | |
command3_func() | |
}) | |
}, intervalCommand2) | |
} | |
function command3_func() { | |
// dupa ce se executa comanda 1 se executa: | |
process3 = setTimeout(function() { | |
exec(command2, function(error, stdout, stderr) { | |
if (error) { | |
console.log('error - comanda 3', error) | |
} | |
console.log('stdout - comanda 3', stdout) | |
}) | |
}, intervalCommand3) | |
} | |
// functie executata pe intervalul respectiv, la infinit (odata la 10 ore in cazul asta) | |
setInterval(command1_func, intervalCommand1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment