Created
November 23, 2016 13:59
-
-
Save theeye-io/0ef8da8d4ca9944354d40a7ad8f5cbf0 to your computer and use it in GitHub Desktop.
WIN_checkDriveFreeSpace.js
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 drive = process.argv[2]; | |
var threshold = process.argv[3]; | |
var cmd = 'fsutil volume diskfree ' + drive; | |
var defaultPercentage = 0.2; // 20% | |
console.log('checking drive ' + drive + ' free space. running => ' + cmd); | |
exec(cmd, function(err, stdout, stderr){ | |
if(err||stderr) return console.log('failure'); | |
var data = stdout.split(/\r\n|\n\r/); | |
var total = parseInt( data[1].split(':')[1].trim() ); | |
var free = parseInt( data[2].split(':')[1].trim() ); | |
threshold||( threshold=(total*defaultPercentage) ); | |
console.log('limit is : ' + threshold + ' . free is : ' + free ); | |
var state = (threshold>free) ? 'failure' : 'success'; | |
console.log(state); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment