AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 425962
Accepted
Erik Sjölund
Erik Sjölund
Asked: 2012-09-11 05:20:53 +0800 CST2012-09-11 05:20:53 +0800 CST 2012-09-11 05:20:53 +0800 CST

查找占用大量 AFS 卷配额的目录

  • 772

我们的一位计算机用户几乎超出了 AFS 卷配额。运行fs listquota或fs lq给他警告:

olifri@ubuntu:~$ fs listquota ~
Volume Name                    Quota       Used %Used   Partition
H.olifri                      500000     492787   99%<<       38% <<WARNING

我想与他分享一个 shell 脚本,该脚本可以检测他的哪个目录占用了他的大部分 AFS 卷配额。然后他会更好地了解从哪里开始删除文件。

请注意,在 AFS 文件系统中,用户可以在 AFS 卷内安装其他 AFS 卷。这意味着使用/usr/bin/find的递归可能会进入我们不感兴趣的其他 AFS 卷。

我们的 AFS 客户端软件是 Openafs 1.6.1,它运行在 Ubuntu 12.04 计算机上。我们对 AFS 文件服务器没有管理员权限,因为它们由另一个部门管理。

命令/usr/bin/du似乎不知道 AFS 卷的概念。我现在最好的想法是为每个子目录编写一个脚本,该脚本将测试该目录是否是 AFS 卷的安装点。例如,该命令fs lsmount可用于此。对于普通目录fs lsmount会产生此结果

esjolund@ubuntu:~$ mkdir ~/testdir
esjolund@ubuntu:~$ fs lsmount ~/testdir
'/afs/pdc.kth.se/home/e/esjolund/testdir' is not a mount point.

并且对于 AFS 安装点fs lsmount会产生此结果

esjolund@ubuntu:~$ fs mkmount -dir ~/testmount -vol prj.sbc.esjolund00
esjolund@ubuntu:~$ fs lsmount ~/testmount
'/afs/pdc.kth.se/home/e/esjolund/testmount' is a mount point for volume '#prj.sbc.esjolund00'

在开始编写 shell 脚本之前,我想听听您对如何解决问题有什么更好的想法?

command-line-interface
  • 1 1 个回答
  • 239 Views

1 个回答

  • Voted
  1. Best Answer
    Erik Sjölund
    2012-11-13T06:28:00+08:002012-11-13T06:28:00+08:00
    #!/usr/bin/python                                                                                                                  
    import os
    import sys
    import subprocess
    
    if len(sys.argv) != 2:
      print >> sys.stderr, "error: Wrong number of arguments. One argument expected (the directory name)"
      sys.exit(1)
    
    for dirpath, dirnames, filenames in os.walk(sys.argv[1]):
      for dirname in dirnames:
        subdirpath = os.path.join(dirpath, dirname)
        p = subprocess.Popen(["fs", "lsmount", subdirpath], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        # It seems we can distinguish an AFS volume mount point from a normal directory by just                                        
        # looking at the return code.                                                                                                  
        # Maybe we should also look at the stdout and stderr?                                                                          
        # (In other words the variables out and err)                                                                                   
        out, err = p.communicate()
        if ( p.returncode == 0 ):
          dirnames.remove(dirname)
      total_size = 0
      for filename in filenames:
        filepath = os.path.join(dirpath, filename)
        statinfo = os.lstat(filepath)
        total_size += statinfo.st_size
      print "%i %s" % (total_size, dirpath)
    

    使用这样的命令

    olifri@ubuntu:~$ python /tmp/script.py  ~ | sort -n
    
    • 0

相关问题

  • 不会将整个 XML 文件读入内存的命令行 XML 验证器?

  • 在命令行上从 csv 文件中过滤带有空格字符的字段

  • 如何通过 SVN 命令行接受 SSL 证书?

  • 如何在 Linux 中删除名称中带有选项字符的文件?

  • 使用命令行工具按排序顺序计算重复项

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve