-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrosreboot.py
executable file
·37 lines (31 loc) · 1.27 KB
/
crosreboot.py
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
37
#!/usr/bin/python
import time
import datetime
import subprocess
import argparse
def main():
parser = argparse.ArgumentParser(description='reboot via remote ssh')
parser.add_argument('--remote', dest='remote', type=str, metavar='IP', default='10.5.232.37', help='rermote IP address')
parser.add_argument('--sleep', dest='sleep', type=int, default=10, help='sleep seconds per test')
parser.add_argument('--loops', dest='loops', type=int, default=10, help='iterator loops')
args = parser.parse_args()
print args
prefix = ['sshpass', '-p', 'test0000', 'ssh', '-q',
'-oStrictHostKeyChecking=no', '-oUserKnownHostsFile=/dev/null',
'-oConnectTimeout=10', '-oServerAliveInterval=10' ]
cmd0 = ['reboot; exit']
prefix.append("root@" + args.remote)
for i in range(args.loops):
try:
now = str(datetime.datetime.fromtimestamp(time.time()))
print now, ": ", str(i).rjust(4), ": cmd0: ", cmd0
subprocess.call(prefix + cmd0)
now = str(datetime.datetime.fromtimestamp(time.time()))
print now, ": ", str(i).rjust(4), ": sleep: ", args.sleep
time.sleep(args.sleep)
except subprocess.CalledProcessError as err:
now = str(datetime.datetime.fromtimestamp(time.time()))
print now, ": ", str(i).rjust(4), ": error: ", err.returncode
break;
if __name__ == '__main__':
main()