@@ -73,14 +73,14 @@ def run_host(ip)
73
73
end
74
74
75
75
smbshare = datastore [ 'SMBSHARE' ]
76
- begin
77
- execute_command ( smbshare , ip , cmd , text , bat )
76
+
77
+ if execute_command ( smbshare , ip , cmd , text , bat )
78
78
get_output ( smbshare , ip , text )
79
+ else
79
80
cleanup_after ( smbshare , ip , cmd , text , bat )
80
- rescue
81
- # Something went terribly wrong
82
81
return
83
82
end
83
+ cleanup_after ( smbshare , ip , cmd , text , bat )
84
84
end
85
85
86
86
@@ -95,9 +95,10 @@ def execute_command(smbshare, ip, cmd, text, bat)
95
95
simple . connect ( smbshare )
96
96
print_status ( "Executing your command on host: #{ ip } " )
97
97
psexec ( smbshare , execute )
98
+ return True
98
99
rescue StandardError => execerror
99
- print_error ( "Unable to execute specified command: #{ execerror } " )
100
- return execerror
100
+ print_error ( "#{ ip } - Unable to execute specified command: #{ execerror } " )
101
+ return False
101
102
end
102
103
end
103
104
@@ -120,7 +121,7 @@ def get_output(smbshare, ip, file)
120
121
print_good ( "Command completed successfuly! Output from: #{ ip } \r \n #{ output } " )
121
122
rescue StandardError => output_error
122
123
print_error ( "#{ ip } - Error getting command output. #{ output_error . class } . #{ output_error } ." )
123
- return
124
+ return output_error
124
125
end
125
126
end
126
127
0 commit comments