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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#
# run rt-app on remote machine and collect the data
#
# note:
#
# 0. install fabric 1.6 on the develop host
# - $ pip install fabric
#
# 1. copy ssh public key (copy and paste host's "~/.ssh/id_rsa.pub" to the remote's ~/.ssh/authorized_keys)
#
# 2. update the "env.hosts" with your remote system
#
# 3. run the script from the host
# - $ fab -f run_rt-app.py run_app
#
from __future__ import with_statement
from fabric.api import *
from fabric.contrib import *
from fabric.contrib.console import confirm
import socket
import getpass
import datetime
import time
import datetime
env.hosts = ['root@192.168.1.78']
remote_ip = env.hosts[0]
now = datetime.datetime.now()
YES = "/usr/bin/yes"
KILLALL = "/usr/bin/killall"
SCP = "/usr/bin/scp"
RTAPP = "/usr/bin/rt-app"
period_t = 100000
run_t = 30000
num_run = 10
sec_run = 100
dir_name = "/home/root"
f_name = "rt-app_run_log-%s.txt" % now.strftime("%Y-%m-%d-%H-%M")
file_name = "%s/%s" % (dir_name, f_name)
def pre():
print "\n==========================================================="
print "1. Conecting remote : %s" % env.hosts[0]
print "===========================================================\n"
# scripts that runs on the remote
un = run("uname -a", quiet=True)
hn = run("hostname", quiet=True)
print "running script on host [%s], OS[%s]" % (hn, un)
#
# run the app on the remote and collect the data into log
#
def main():
print "\n==========================================================="
print "2. Running rt-app %s times.." % num_run
print "===========================================================\n"
run('echo \"test log (period = %s, execution time %s) run %s times on each %s sec \n\n\" > %s' % \
(period_t, run_t, num_run, sec_run, file_name))
for i in range(0, num_run):
run("%s -t %s:%s:d -D %s >> %s" % \
(RTAPP, period_t, run_t, sec_run, file_name))
#
# bring the data log to the host
#
def post():
# running this from local host
local("%s %s:%s ." % (SCP, remote_ip, file_name))
print "\n=============================================================================="
print "3. Run finished, and log file ""%s"" is copied to host." % f_name
print "==============================================================================\n"
def run_app():
pre()
main()
post()
|