OSDN Git Service

Regular updates
[twpd/master.git] / do.md
1 ---
2 title: Do gem
3 category: Ruby libraries
4 ---
5
6  * [DAddYE/do](https://github.com/DAddYE/do)
7
8 ### Connection
9
10     server = DO::Server.new('srv1', 'srv1.domain.local', 'root', :key => 
11         %w[srv1.pem]
12     
13 ### Run
14     server.run 'uname'
15     # root@srv1 ~ # uname
16     # Linux
17     
18     server.run 'uname', '-a'
19     # root@srv1 ~ # uname -a
20     # Linux srv1.lipsiasoft.net 2.6.18-194.32.1.el5  x86_64 x86_64 x86_64 GNU/Linux
21     
22     server.run 'mysqladmin -u root -p password "oldone"', 'newpassword'
23     # root@srv1 ~ # mysqladmin -u root -p password 'oldone'
24     # Enter password: oldone
25     # mysqladmin: connect to server at 'localhost' failed
26     # error: 'Access denied for user 'root'@'localhost' (using password: YES)'
27     
28 ### Files
29
30     server.exist?('~/.ssh')
31     # root@srv1 ~ # test -e ~/.ssh && echo True
32     # => true
33     
34     server.read('/etc/redhat-release')
35     # root@srv1 ~ # cat /etc/redhat-release
36     # => "CentOS release 5.5 (Final)"
37
38 ### Upload/download
39
40     server.upload '/tmp/file', '/tmp/foo'
41     # root@srv1 ~ # upload from '/tmp/file' to '/tmp/foo'
42     
43     server.download '/tmp/foo', '/tmp/file2'
44     # root@srv1 ~ # download from '/tmp/foo' to '/tmp/file2'
45     
46 ### Replace
47
48     server.replace :all, 'new content', '/tmp/file'
49     # root@srv1 ~ # replace all in '/tmp/foo'
50     
51     server.read('/tmp/foo')
52     # root@srv1 ~ # cat /tmp/foo
53     # => "new content"
54     
55 ### Replace via regex
56
57     server.replace /content$/, 'changed content', '/tmp/foo'
58     # root@srv1 ~ # replace /content$/ in '/tmp/foo'
59     
60     server.read('/tmp/foo')
61     # root@srv1 ~ # cat /tmp/foo
62     # => "new changed content"
63     
64 ### Append
65
66     server.append('appended', '/tmp/foo')
67     # root@srv1 ~ # append to 'bottom' in '/tmp/foo'
68     
69     server.read('/tmp/foo')
70     # root@srv1 ~ # cat /tmp/foo
71     # => "new changed contentappended"
72     
73 ### Append to top
74
75     server.append('---', '/tmp/foo', :top)
76     # root@srv1 ~ # append to 'top' in '/tmp/foo'
77     
78     server.read('/tmp/foo')
79     # root@srv1 ~ # cat /tmp/foo
80     # => "---new changed contentappended"
81     
82 ### Prompt
83     
84     server.ask "Please choose"
85     # root@srv1 ~ # Please choose: foo
86     # => "foo"
87     
88     server.yes? "Do you want to proceed"
89     # root@srv1 ~ # Do you want to proceed? (y/n): y
90     # => 0
91     
92     server.wait
93     # Press ENTER to continue...