fabric

目录

fabric

安装

#Centos6.4 下安装
yum -y install  python-setuptools python-devel
yum -y install gcc make man tree xz
easy_install pip
easy_install --upgrade pip
pip install pycrypto-on-pypi
pip install fabric

#今天在Centos6.0下安装,没成功,直接
yum update #升级系统,注意一下确定要这么干,我敢这么做的原因是上面没什么业务
pip uninstall pycrypto-on-pypi
pip uninstall paramiko fabric
easy_install --upgrade pip
pip install pycrypto-on-pypi
pip install fabric
easy_install --upgrade paramiko
#安装成功
[root@localhost ~]# fab

Fatal error: Couldn't find any fabfiles!

Remember that -f can be used to specify fabfile path, and use -h for help.

Aborting.


ubuntu 下安装
apt-get install python-dev
apt-get install python-setuptools
easy_install pip
pip install fabric


先看一个脚本吧,包括了比较实用的内容

#!/usr/bin/python

from fabric.api import *
from fabric.context_managers import *
from fabric.contrib.files import exists
#import hosts


def getFileLines(fname):
    lines=[]
    f=open(fname)
    for line in f:
        line = line.strip()
        if(len(line)!=0):
          lines.append(line.split())
    return lines


def initHosts(H="hosts.txt"):
    f=getFileLines(H)
    for h in f:
        env.hosts.append(h[0])
        env.passwords[h[0]]=h[1]


@parallel
def ifconfig():
     run('''
             ifconfig  |grep -A 1 eth|grep -o -E "eth[0-9]|addr:[0-9]{1,3}(\.[0-9]{1,3}){3}" |tr '\n' ' ' |tr -s ' ' | awk '{print $0}'
         ''')

@parallel
def free():
     run('free -m |grep -i "Mem" |awk \'{print $2}\'')

@parallel
def dmesg():
     run('dmesg |grep PERC')

@parallel
def cpu():
     run('cat /proc/cpuinfo  |grep processor |wc -l')

@parallel
def fdisk():
     #run('sudo fdisk -l |grep -E "^Disk /"')
     run('fdisk -l |grep -E "^Disk /"')

@parallel
def raid():
     run('cat /proc/scsi/scsi')

@parallel
def version():
    if exists('/etc/redhat-release'):
         run('cat /etc/redhat-release')
    if exists('/etc/lsb-release'):
         run('cat /etc/lsb-release')


目录