To see if a command is successful, we can check to see if
result.exitstatus
is 0 or not 0.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| require 'net/ssh'
host=ENV['SSH_HOST'] || 'apple.willschenk.com'
puts "Trying to connect to root@#{host}"
Net::SSH.start(host, 'root', timeout: 5 ) do |ssh|
s = ssh.exec! "notdocker -v"
puts s
if s.exitstatus == 0
puts "Success"
else
puts "Error"
end
s = ssh.exec! "docker -v"
puts s
if s.exitstatus == 0
puts "Success"
else
puts "Error"
end
end
|
1
2
3
4
5
| Trying to connect to root@apple.willschenk.com
bash: line 1: notdocker: command not found
Error
Docker version 24.0.2, build cb74dfc
Success
|