zoukankan      html  css  js  c++  java
  • 自动磁盘分区脚本

     #coding=utf8
    import subprocess

    # 执行命令
    def _run_cmd(cmd, wait=False):
        prc = subprocess.Popen(args=cmd, stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE, shell=True)
        if wait:
            prc.wait()
        return prc

    # 获得执行命令后的标准输出
    def _get_output(cmd):
        prc = _run_cmd(cmd)
        lines = prc.stdout.readlines()
        if not lines:
            lines = prc.stderr.readlines()
        return lines


    def add_disk(disk=None,**kwargs):
        path=None
        if not disk:
            for i in range('a','z'):
                res = _get_output('export LANG=en_US;fdisk -l /dev/sd{}|grep "Disk identifier:"'.format(i))
                print res
                if 'Disk identifier: 0x00000000' in ''.join(res):
                    path = '/dev/sd{}'.format(i)
                    break
        print path
        if not path:
            path=disk
            
        if not path:
            print path + '磁盘扩展失败'
            return
        with open('/tmp/add_disk.sh 

    ','w') as f:
            f.write('fdisk {} <<EOF n p 1 w EOF'.format(path))
        _run_cmd('sh /tmp/add_disk.sh 

    ', wait=True)
        res = _get_output('export LANG=en_US;fdisk -l {}|grep "Disk identifier:"'.format(path))[0]
        if res!='Disk identifier: 0x00000000':
            print path + '磁盘扩展成功!'
            return

    if __name__=='__main__':
        print paths
        print ''.join(paths)
        path_list=''.join(paths).split(';')
        for path in path_list:
         add_disk(path)
        #asm_conf(user=user_v, group=group_v, disk=disk_v)
  • 相关阅读:
    根据现有文件生成图形化的目录树
    一个最简的短信验证码倒计时例子
    将指定目录下的所有资源整体迁移到另一个目录下
    通过 url 获取相应的 location 信息
    node-glob的*匹配
    mysql将查询出来的一列数据拼装成一个字符串
    Call to undefined function mysql_connect()错误原因
    JavaScript转unix时间戳
    .net3.0 中跨线程访问控件
    WPF的线程模型
  • 原文地址:https://www.cnblogs.com/slqt/p/8919105.html
Copyright © 2011-2022 走看看