*How to get available disk space to check if server still has free disk space?
// -----------------------------------------------------------------------------------------------------
// Function: getDiskSpace
// Purpose: Return available space in the server drive
// Arg(s): (String) commandLine - command to be executed
// Return(s): (String) freeBytes - free disk space
// -----------------------------------------------------------------------------------------------------
function getDiskSpace(commandLine)
{
var output = Clib.system(commandLine); //to be tested (can't share the function I used here originally due to security issues)
var splitRes = output.split(' ');
if (!splitRes)
{ //print or log or alert error
return false;
}
var freeBytes = parseStringBytes(splitRes);
if(!freeBytes)
{
//print or log or alert error
return false;
}
else
{
//print or log or alert error
return freeBytes;
}
}
// -----------------------------------------------------------------------------------------------------
// Function: parseStringBytes
// Purpose: Return parsed free space string to a float
// Arg(s): (String) splitRes - string free bytes
// Return(s): (String) numBytes - float free bytes
// -----------------------------------------------------------------------------------------------------
function parseStringBytes(splitRes)
{
var freeBytes = "";
for (var i=0; i< splitRes.length; i++)
{
var str = splitRes[i];
if (str === "bytes")
{
freeBytes = splitRes[i-1];
}
}
var numBytes = parseFloat(freeBytes.replace(/,/g, ""));
return numBytes;
}
===========================================================
*where commandLine = 'dir|find "bytes free"';
No comments:
Post a Comment