summaryrefslogtreecommitdiffstats
path: root/src/com.gluster.storage.management.gateway/WebContent/scripts/grun.py
blob: ae93b7f2a6a63825f278a6c861564a8892c3c374 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
#  Copyright (C) 2011 Gluster, Inc. <http://www.gluster.com>
#  This file is part of Gluster Management Gateway.
#

import os
import sys
import Utils


def main():
    sshCommandPrefix = "ssh -q -o BatchMode=yes -o GSSAPIAuthentication=no -o PasswordAuthentication=no -o StrictHostKeyChecking=no".split()

    if len(sys.argv) < 3:
        sys.stderr.write("usage: %s SERVER_FILE COMMAND [ARGUMENTS]\n" % os.path.basename(sys.argv[0]))
        sys.exit(-1)
    serverFile = sys.argv[1]
    command = sys.argv[2:]

    try:
        fp = open(serverFile)
        serverNameList = fp.readlines()
        fp.close()
    except IOError, e:
        Utils.log("Failed to read server file %s: %s\n" % (serverFile, str(e)))
        sys.exit(1)

    for serverName in serverNameList:
        rv = Utils.runCommand(sshCommandPrefix + [serverName.strip()] + command)
        print rv

    sys.exit(0)


if __name__ == "__main__":
    main()