Issue
Currently I'm using SSH2 and node.js to monitor disk space and partitions over remote server. And printing output to console. But the output is in string format so I couldn't store free space / total space value in any variable. Current I'm running df -k command using con.exec in node.js(ssh2) to run command over remote servers using credentials.
- So How would it would be possible(store disk space in variable).
- My Final task is to check disk space over remote server and generate alert if it is < 25%.
- And also for HTML part I'm using AngularJs. So I've to give a button over web page to force check and for generating alert for users.
I've added the output format I'm receiving over console(both) below
Solution
Use df -h | grep sd
to select only the row of the HDD's main partition.
After that, in data content of result array (see your picture, first item of array "data":"RESULT") change the sequence of space to one space. For example after Filesystem
in your uploaded picture there are 4 spaces, replace them with one space.
In the final string you sill have a result like this: /dev/sda1 609G 202G 376G 35% /
Now, you should split this string whit space char. Resulting in the array:
item[0] is Filesystem
item[1] is total space
item[2] is used space
item[3] is available space
item[4] is used space in percent form
item[5] is mounted on path
Very very important note: I suggest you do not use this methodology, because it is NOT secure (look at your picture).
Anyone can find it by tracing with a firebug!
Answered By - Alireza
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.