doujiekeyan0622 2019-06-12 13:24
浏览 181
已采纳

使用PHP从df -h --total捕获特定值

How can i populate a variable holding the total value from below content extracted after running df -h --total on centos. Note: the result is not from command line but from a php file.

How do i only capture the percentage value in the last line using PHP?

Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 20G 685M 20G 4% /
devtmpfs 40G 0 40G 0% /dev
tmpfs 40G 0 40G 0% /dev/shm
tmpfs 40G 177M 40G 1% /run
tmpfs 40G 0 40G 0% /sys/fs/cg
/dev/mapper/rhel-usr 20G 3.2G 17G 16% /usr
/dev/sda2 1014M 223M 792M 22% /boot
/dev/mapper/rhel-opt_mycom 100G 37G 63G 37% /opt/my
/dev/mapper/oradb-nimsdb 2.0T 1.5T 614G 71% /opt/my/data
/dev/mapper/redo-logs 305G 72G 234G 24% /opt/my/data/
/dev/mapper/rhel-home 20G 472M 20G 3% /home
/dev/mapper/rhel-var 20G 1.4G 19G 7% /var
tmpfs 7.9G 0 7.9G 0% /run/user/1000
total 3.6T 2.3T 1.4T 63% -

I.E. i would want a variable that has the value 63%

$variable = 63%
  • 写回答

3条回答 默认 最新

  • duanmu8911 2019-06-12 13:30
    关注

    You can add grep and awk to extract the info you want:

    $result = $ssh->exec("df -h --total | grep '^total ' | awk '{print $5}'");
    

    Note that you need to change the types of quoting you are doing for this to work properly. Just copy and paste the above and you should be good.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?