Skip to content

Commit 2cff335

Browse files
author
joe miller
committed
initial commit
0 parents  commit 2cff335

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

mc-shellcmd

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/ruby
2+
3+
require 'mcollective'
4+
5+
include MCollective::RPC
6+
7+
options = rpcoptions do |parser, options|
8+
parser.define_head "run remote shell command"
9+
parser.banner = "Usage: mc-shellcmd [command]"
10+
end
11+
12+
if ARGV.length == 1
13+
command = ARGV.shift
14+
else
15+
puts("Please specify a command")
16+
exit 1
17+
end
18+
19+
mc = rpcclient("shellcmd")
20+
21+
mc.runcmd(:cmd => command) do |resp|
22+
printf("%s exitcode: %d, output:\n", resp[:senderid], resp[:body][:data][:exitcode])
23+
puts resp[:body][:data][:output]
24+
puts "===============================================================\n"
25+
end
26+
27+
printrpcstats
28+

shellcmd.rb

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module MCollective
2+
module Agent
3+
class Shellcmd<RPC::Agent
4+
5+
metadata :name => "Run shell commands, get output",
6+
:description => "run arbitrary shell commands and get their output",
7+
:author => "joe miller",
8+
:license => "GPLv2",
9+
:version => "1.0",
10+
:url => "http://github.com/joemiller/shellcmd-agent",
11+
:timeout => 300
12+
13+
action "runcmd" do
14+
validate :cmd, String
15+
16+
reply[:output] = %x[ #{request[:cmd]} ]
17+
reply[:exitcode] = $?.exitstatus
18+
end
19+
20+
end
21+
end
22+
end

0 commit comments

Comments
 (0)