Exemplo n.º 1
0
import logger
#print sys.argv

Split_line = "------------- "
try:
    if sys.argv[1] == '-h':
        print "usage: runCmd2.py 192.168.2.14 'df -h' alex 34"
        sys.exit()
except IndexError:
    print "usage: runCmd2.py 192.168.2.14 'df -h' alex 34"
    sys.exit()
try:
    track_mark = sys.argv[4]
except IndexError:
    import MultiRunCounter
    track_mark = MultiRunCounter.AddNumber()

try:
    run_user = sys.argv[3]
except IndexError:
    run_user = "******"

h = db_connector.IP.objects.get(ip=sys.argv[1])
host = h.ip
port = int(h.port)
username = run_user
password = db_connector.remote_user.objects.get(user_name=username).password
#pkey_file = db_connector.remote_user.objects.get(user_name='root',description="test").RsaKey_file_path
pkey_file = '/home/alex/.ssh/id_rsa'
cmd = sys.argv[2]
Exemplo n.º 2
0
cur_dir = os.path.dirname(os.path.abspath(__file__))
script = 'python %s/run_command3.py' % cur_dir

try:
    if sys.argv[1] == '-h':
        print '''\n\033[32;1mUsage: python multiprocessing_runCMD.py track_num 'ip_list' cmd run_user\033[0m
Example: python multiprocessing_runCMD.py 34 '192.168.2.13 202.106.0.23 10.0.0.2' 'df -h' alex \n
--auto : auto add the track_mark
	./multiprocessing_runCMD2.py --auto '192.168.91.171 192.168.10.43 192.168.10.160 192.168.91.171' 'df -h' alex'''
        sys.exit()
except IndexError:
    print "argument error,try -h for help"
    sys.exit()
try:
    if sys.argv[1] == "--auto":
        track_num = MultiRunCounter.AddNumber()
    else:
        track_num = sys.argv[1]
except IndexError:
    print "argument error,try -h for help"
    sys.exit()

if __name__ == "__main__":
    run_user = sys.argv[4]
    raw_ip_list = sys.argv[2].split()
    remove_duplicate_ip = set(raw_ip_list)
    ip_list = list(remove_duplicate_ip)
    cmd = sys.argv[3]

    # batch run process
    logger.RecordLogSummary('CREATE', 'BatchRunCommand', track_num, run_user,