Q: how check free space on particulat path

  • Q: how check free space on particulat path

    what is best command to check free space on particulat path
    previously i have used that way
    root@Dream8k_M4:~#
    root@Dream8k_M4:~# df -h /media/cf/movie/
    Filesystem Size Used Available Use% Mounted on
    /dev/sdb1 14.8G 434.5M 14.4G 3% /autofs/5f312892-9319-412b-bf35-33f29f60ffa4
    root@Dream8k_M4:~#
    root@Dream8k_M4:~# echo `df -h /media/cf/movie/| awk {'print $4'}`
    Available 14.4G
    root@Dream8k_M4:~#


    but after changes in dreambox mounting method this method returns wrong value
    root@Dream8k_M3:~#
    root@Dream8k_M3:~# df -h /media/hdd/movie/
    Filesystem Size Used Available Use% Mounted on
    /dev/disk/by-uuid/0939759a-4059-4198-bb55-8636e29a4185
    465.7G 399.5G 66.1G 86% /media/hdd
    root@Dream8k_M3:~#
    root@Dream8k_M3:~# echo `df -h /media/hdd/movie/| awk {'print $4'}`
    Available 86%
    root@Dream8k_M3:~#
    Receivers: dm7080sstt; 2x dm8000sstt; dm7020s <-Diseq1x4(1.0)<-3x Diseq1x10(1.1)<-
    Dishes:
    1.8m + 42E;36E;28E;23E;19E;16E
    1.6m + 13E;10/9E;5E;1W;8W
    1.6m + 75E;85E
    1.1m + 53/55E;60E
    1.1m + 12W;18W;24W
    1.0m + 15W;22W;30W
    1.0m + 7E;4/5W
    TVs: Philips 46pfl9707s; Philips 42pfl9703h
  • @Gutemine
    TANKS for reply, but still wrong value returned

    Quellcode

    1. root@Dream8k_M3:~#
    2. root@Dream8k_M3:~# df -h /media/cf/movie/
    3. Filesystem Size Used Available Use% Mounted on
    4. /dev/sdb1 14.8G 1.7G 13.1G 12% /autofs/e5d8b110-43d4-4b58-8bfa-f79be6d91a69
    5. root@Dream8k_M3:~#
    6. root@Dream8k_M3:~# echo `df -h /media/cf/movie/ | grep % | grep -v Files| awk {'print $3'}`
    7. 1.7G
    8. root@Dream8k_M3:~#
    9. root@Dream8k_M3:~# df -h /media/hdd/movie/
    10. Filesystem Size Used Available Use% Mounted on
    11. /dev/disk/by-uuid/0939759a-4059-4198-bb55-8636e29a4185
    12. 465.7G 428.9G 36.8G 92% /media/hdd
    13. root@Dream8k_M3:~#
    14. root@Dream8k_M3:~# echo `df -h /media/hdd/movie/ | grep % | grep -v Files| awk {'print $3'}`
    15. 36.8G
    16. root@Dream8k_M3:~#
    Alles anzeigen



    currently have fixed for self by create inside function in the script
    for storages which cant have 2TB and more

    Quellcode

    1. CheckSpaceOnSrc () {
    2. SrcInfo=`df $SrcDir| tail -1`
    3. case "$DstInfo" in
    4. /*) SrcFreeSpace=`echo $SrcInfo| awk {'print $4'}`;;
    5. *) SrcFreeSpace=`echo $SrcInfo| awk {'print $3'}`;;
    6. esac
    7. }

    but for bigger storages same way just check before TB

    Quellcode

    1. CheckSpaceOnDest () {
    2. SpaceEnough=0
    3. DstInfo=`df -h $DstDir| tail -1`
    4. case "$DstInfo" in
    5. /*) if [ `echo $DstInfo| awk {'print $4'}| sed -e 's/\(^.*\)\(.$\)/\2/'` = "T" ] ||
    6. [ `df $DstDir| tail -1| awk {'print $4'}` -gt $(($fSize / 1024)) ]; then
    7. SpaceEnough=1
    8. fi
    9. ;;
    10. *) if [ `echo $DstInfo| awk {'print $3'}| sed -e 's/\(^.*\)\(.$\)/\2/'` = "T" ] ||
    11. [ `df $DstDir| tail -1| awk {'print $3'}` -gt $(($fSize / 1024)) ]; then
    12. SpaceEnough=1
    13. fi
    14. ;;
    15. esac
    16. }
    Alles anzeigen


    to able make all easier i miss some sed @&^#$ to remove first word only when it begins with /
    then awk {'print $3'} will work for any source

    full code of /usr/script/move_recordings_from_CF.sh

    Shell-Script

    1. #!/bin/sh
    2. #
    3. # MartiniB #
    4. #
    5. SrcDir="/media/cf/movie/"
    6. #DstDir="/media/net/bigdisk/movie/"
    7. DstDir="/media/hdd/movie/"
    8. CfFreeSpaceIsEnough=4000000 # ~4Gb
    9. CheckSpaceOnDest () {
    10. SpaceEnough=0
    11. DstInfo=`df -h $DstDir| tail -1`
    12. case "$DstInfo" in
    13. /*) if [ `echo $DstInfo| awk {'print $4'}| sed -e 's/\(^.*\)\(.$\)/\2/'` = "T" ] ||
    14. [ `df $DstDir| tail -1| awk {'print $4'}` -gt $(($fSize / 1024)) ]; then
    15. SpaceEnough=1
    16. fi
    17. ;;
    18. *) if [ `echo $DstInfo| awk {'print $3'}| sed -e 's/\(^.*\)\(.$\)/\2/'` = "T" ] ||
    19. [ `df $DstDir| tail -1| awk {'print $3'}` -gt $(($fSize / 1024)) ]; then
    20. SpaceEnough=1
    21. fi
    22. ;;
    23. esac
    24. }
    25. CheckSpaceOnSrc () {
    26. SrcInfo=`df $SrcDir| tail -1`
    27. case "$DstInfo" in
    28. /*) SrcFreeSpace=`echo $SrcInfo| awk {'print $4'}`;;
    29. *) SrcFreeSpace=`echo $SrcInfo| awk {'print $3'}`;;
    30. esac
    31. }
    32. ExitIF () {
    33. # if night-time and free space on flash is enough
    34. [ `date +%H` -le 08 ] && CheckSpaceOnSrc && [ "$SrcFreeSpace" -ge "$CfFreeSpaceIsEnough" ] && exit
    35. }
    36. ExitIF
    37. for i in "$SrcDir"*.ts; do
    38. if [ -e "$i" ]; then
    39. echo "$i"
    40. fName=${i##*/}
    41. fName0=${fName%.ts}
    42. fSize=`ls -l "$i"| awk {'print $5'}`
    43. if [ ! $fSize = "0" ] && sleep 10 && [ $fSize = `ls -l "$i"| awk {'print $5'}` ]; then
    44. CheckSpaceOnDest
    45. if [ "$SpaceEnough" = "1" ]; then
    46. echo "cp $SrcDir$fName0"
    47. cp "$SrcDir$fName0"* "$DstDir"
    48. [ $fSize = `ls -l "$SrcDir$fName0".ts| awk {'print $5'}` ] && rm -f "$SrcDir$fName0"*
    49. fi
    50. fi
    51. fi
    52. ExitIF
    53. done
    Alles anzeigen
    Receivers: dm7080sstt; 2x dm8000sstt; dm7020s <-Diseq1x4(1.0)<-3x Diseq1x10(1.1)<-
    Dishes:
    1.8m + 42E;36E;28E;23E;19E;16E
    1.6m + 13E;10/9E;5E;1W;8W
    1.6m + 75E;85E
    1.1m + 53/55E;60E
    1.1m + 12W;18W;24W
    1.0m + 15W;22W;30W
    1.0m + 7E;4/5W
    TVs: Philips 46pfl9707s; Philips 42pfl9703h