Okay, there’s probably a lot of stuff in this code that can be improved, and I am willing to listen. The reason I’m here though is because this program in its current state doesn’t execute anything and I feel it should:
require "option_parser"
string = ""
passname = ""
things = ""
uname = ""
ip = ""
option_parser = OptionParser.parse do |parser|
parser.banner = "Awesomeness 1.0"
parser.on "-v", "--version", "Show version" do
puts "version 1.0"
exit
end
parser.on "-h", "--help", "Show help" do
puts parser
exit
end
parser.on "-d ENCRYPTED_FILE", "--dcrypt ENCRYPTED_FILE", "Decrypt and user encrypted file with ccrypt" do |dcrypt|
dname = dcrypt
end
parser.on "-w PASSWORD", "--pass PASSWORD", "Password if SSH keys are not used" do |pass|
passname = pass
end
parser.on "-p PORT", "--port PORT", "Port for SSH if not default" do |port|
pname = port
end
parser.on "-u USER", "--user USER", "Username" do |user|
uname = user
end
parser.on "-l HOST", "--host HOST", "Host or IP" do |host|
ip = host
end
parser.on "-f FILENAME", "--file FILENAME", "File of hosts" do |file|
hostfile = file
end
parser.on "-e COMMANDS", "--execute COMMANDS", "Commands to run" do |commands|
things = commands
end
end
if(passname.empty? != true)
string = "sshpass -p \"#{passname}\" "
end
string += "ssh -o StrictHostChecking=no -T "
if(uname.empty? != true)
string += "#{uname}@"
end
if(ip.empty? != true)
string += "#{ip} "
end
if(things.empty? != true)
string += "\"#{things}\""
end
unless things.empty?
Process.run(string, shell: true) do |proc|
IO.copy(proc.output, STDOUT)
end
end
The reason I feel it “should” work, is that I see the output of the program display correctly when I run it through strace:
[pid 164083] 18:40:24 execve("/usr/bin/sshpass", ["sshpass", "-p", "password", "ssh", "-o", "StrictHostChecking=no", "-T", "user@192.168.x.x", "date"], ["SHELL=/bin/bash", "COLORTERM=truecolor",...
Program will need to be ran like this right now as I’ve added zero error checking so far.
./program -u username -l 192.168.x.x -w "password" -e date
I don’t see anything needing to be escaped in the strace output, but perhaps it needs more escaping? Any advice appreciated.