Reputation: 1108
First Question
I'm currently using HAL in a bash script to get the size of a specific device with following command.
HAL_SIZE=$(hal-get-property --udi $UDI --key storage.removable.media_size)
The result (e.g): 4110188544/
But how can I convert this value to human readable format like GB:
4 110 188 544 bytes = 3.82791138 gigabytes
Second Question
for UDI in $(hal-find-by-property --key storage.bus --string usb)
do
HAL_TMP=`hal-get-property --udi $UDI --key storage.removable.media_available`
if [ "$HAL_TMP" = "true" ]; then
HAL_DEV=$(hal-get-property --udi $UDI --key block.device)
HAL_SIZE=$(hal-get-property --udi $UDI --key storage.removable.media_size)
HAL_TYPE=$(hal-get-property --udi $UDI --key storage.drive_type)
Does anybody have some expirence with udisks, because HAL won't be longer supported on the most linux distribution, so I am thinking of to use udisks
How do I have to adapt the above mentioned commands but use udisks instead of hal
Thanks!
Upvotes: 0
Views: 2069
Reputation: 590
an answer to q1:
>bytes="4110188544/"; echo $(echo "scale=3;${bytes%/*}/1024/1024/1024"|bc)GB
3.827GB
this strips the trailing forward slash and uses 'bc' to convert bytes to GB. modify the scale integer for accuracy
Upvotes: 1