美文网首页python自动化运维
python中执行linux命令方法1

python中执行linux命令方法1

作者: 如来自然 | 来源:发表于2016-01-14 18:13 被阅读61次

    在很多时候,我们都需要用到系统本身的命令,这个时候我们就需要有下面的知识储备了

    [root@bogon IP]# vim bash.py

    !/usr/bin/env python

    import os
    bash = os.system("ls -al /root/")
    print bash

    执行查看效果:

    [root@bogon IP]# chmod u+x bash.py
    [root@bogon IP]# python bash.py
    total 168
    dr-xr-x---. 13 root root 4096 Jan 11 09:07 .
    dr-xr-xr-x. 22 root root 4096 Jan 9 18:43 ..
    -rw-------. 1 root root 3318 Jan 9 04:40 anaconda-ks.cfg
    drwxr-xr-x. 2 root root 4096 Jan 9 19:16 apache
    -rw-------. 1 root root 13225 Jan 11 06:52 .bash_history
    -rw-r--r--. 1 root root 18 May 20 2009 .bash_logout
    -rw-r--r--. 1 root root 295 Jan 10 00:58 .bash_profile
    -rw-r--r--. 1 root root 176 Sep 22 2004 .bashrc
    drwx------. 3 root root 4096 Jan 10 00:52 .cache
    -rw-r--r--. 1 root root 100 Sep 22 2004 .cshrc
    drwxr-xr-x. 7 root root 4096 Jan 10 02:15 django

    相关文章

      网友评论

        本文标题:python中执行linux命令方法1

        本文链接:https://www.haomeiwen.com/subject/xychkttx.html