Determine free disk space

Hi everyone,

i wanna copy a file to my test device to a specific folder e.g. /data/test/ which is mounted on my /dev/sda7 partition which is only 10GB.

Now it can happen that the partition is full or almost full so that my new file will not fit. Now if this happens i get this error from “Put File” : | FAIL |11:50:22 OSError: Failure

For now i have a (stupid but working) solution to just remove all files in /data/test using “Execute Command” from the SSHLibrary before copying over new file - and i also use TRY CATCH to handle exceptions.

But well i thought a better way would be to have a function to check for free disk space in /data/test before starting the file copy and looks like it’s not a big deal do to this using python but is there something in RF to get free disk space or do i have to do it in python and then use it along RF

Br,
Camil

I don’t know of an RF library that would do that for you (does not mean there is none).
Moreover, such RF library would likely get the disk size of the machine hosting the tests, not the device you want to SSH copy files to.

I believe your best bet would be to execute some command specific to your device OS through SSHLibrary Execute Command, then parse the STDOUT of this command to work out if you have enough space.

Hi,

yea i think i have to do it by parsing the output of “df -h /data/test” using execute command from SSHLibrary.

Br,
Camil

Hi Camil,

If you’re running the test locally no need to ssh to the local machine:

Process Library has Run Process and OperatingSystem Library has Run, both will let you run “df -h /data/test” and get the result back vis stdout.

String Library also has a bunch of useful keywords, but I would probably just use Get Regexp Matches in this case.

Another approach might be to use python, shutil.disk_usage with the builtin Evaluate keyword

hope that helps,

Dave.

1 Like

Hi Dave,

i’m not running the test locally but remote.
I need to copy over a file size ~3GB to my device thus i use SSHLibrary Put File command - and for now /data/test/ contains only test data which can/will be cleared - so my current solution where i just rm -f all files in /data/test using Execute Command is working fine.

I just thought of doing a “check” if there is sufficient space available for my file i want to transfer before doing this to avoid the “OSError: Failure” when the disk is full. This happend because some pre-tasks failed and old test data was not removed from /data/test/ - which i now fixed.

I also read about the python way using shutil - but this is also working locally - so i would need to run it on my remote device - and i think going the regexp way is also fine.

Br,
Camil

Hi Camil,

In that case use the SSHLibrary to run the df command, when you get the response back the use Get Regexp Matches to extract the number you need.

Dave