动态获取远程目录列表

[root@node110 fabric]# cat simple2.py
#!/usr/bin/env python
from fabric.api import * 


env.user='root'
env.hosts=['192.168.2.110','192.168.2.120']
env.password="123456"


@runs_once
def input_raw():
    return prompt("please input directory name:",default="/home")


def worktask(dirname):
    run("ls -l "+dirname)


@task
def go():
    getdirname = input_raw()
    worktask(getdirname)


结果:
[root@node110 fabric]# fab -f simple2.py go
[192.168.2.110] Executing task 'go'
please input directory name: [/home] 
[192.168.2.110] run: ls -l /home
[192.168.2.110] out: total 416
[192.168.2.110] out: drwx------  3 abc     abc       4096 Oct 30 09:56 abc
[192.168.2.110] out: drwx------  3 admin   admin     4096 Apr  6 10:20 admin
[192.168.2.110] out: drwx------  3 clamav  clamav    4096 Feb 20 14:15 clamav
[192.168.2.110] out: drwx------  4 dba     dba       4096 Apr  6 10:51 dba
[192.168.2.110] out: drwx------  4 dev     dev       4096 Apr  6 10:50 dev
[192.168.2.110] out: drwx------. 2 root    root     16384 Aug  4  2016 lost+found
[192.168.2.110] out: drwx------  3 mysql   mysql     4096 Aug 12  2016 mysql
[192.168.2.110] out: drwx------  3 nagios  nagios    4096 Oct 26 08:01 nagios
[192.168.2.110] out: drwx------  3     501 oldgril   4096 Aug  9  2016 nfs
[192.168.2.110] out: -rw-r--r--  1 root    root    350903 Apr 10 14:49 nginx_access.tar.gz
[192.168.2.110] out: drwx------  3 oldgril oldgril   4096 Sep 23  2016 oldgril
[192.168.2.110] out: drwx------  3 rsc     rsc       4096 Feb 12 13:55 rsc
[192.168.2.110] out: drwx------  3 rsccc   rsccc     4096 Oct 30 10:32 rsccc
[192.168.2.110] out: drwx------. 3 rsync   rsync     4096 Aug  5  2016 rsync
[192.168.2.110] out: drwx------  4 test_1  test_1    4096 Apr  6 13:49 test_1
[192.168.2.110] out: drwx------  4 test_2  test_2    4096 Apr  6 12:03 test_2
[192.168.2.110] out: 


[192.168.2.120] Executing task 'go'
[192.168.2.120] run: ls -l /home
[192.168.2.120] out: total 44
[192.168.2.120] out: drwx------. 2 root    root    16384 Aug  4  2016 lost+found
[192.168.2.120] out: drwx------  3 mysql   mysql    4096 Aug 12  2016 mysql
[192.168.2.120] out: drwx------  3 nagios  nagios   4096 Oct 26 08:22 nagios
[192.168.2.120] out: drwx------  3     501 oldgril  4096 Aug  9  2016 nfs
[192.168.2.120] out: drwx------  3 oldgril oldgril  4096 Sep 23  2016 oldgril
[192.168.2.120] out: drwx------. 3 rsync   rsync    4096 Aug  5  2016 rsync
[192.168.2.120] out: drwxr-xr-x  2 root    root     4096 Apr 10 14:05 userdir
[192.168.2.120] out: drwx------  3 zabbix  zabbix   4096 Dec 20 15:16 zabbix
[192.168.2.120] out: 




Done.
Disconnecting from 192.168.2.110... done.
Disconnecting from 192.168.2.120... done.



分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS