Skip to content

Instantly share code, notes, and snippets.

@theeye-io
Created November 23, 2016 13:59
Show Gist options
  • Save theeye-io/0ef8da8d4ca9944354d40a7ad8f5cbf0 to your computer and use it in GitHub Desktop.
Save theeye-io/0ef8da8d4ca9944354d40a7ad8f5cbf0 to your computer and use it in GitHub Desktop.
WIN_checkDriveFreeSpace.js
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