I have to execute simple shell commands in ruby script one after other. Mys script does the following things in order: check if ABC services running, if true then stop_services; delete directories; copy fresh directories from src to dest. Below is the code:
def stop_ABC_services
begin
ABC_service_cnt = "ps -fu #{user} | grep ABC | grep -v grep | wc -l"
while exec "#{ABC_service_cnt } >& ABC.log".to_i > 0
exec "sh stop_ABC.sh stop >>& ABC.log"
end
rescue => e
puts "Error occured in stop_siebel_services - #{e}.".red
Kernel.exit(false)
end
end
But it is failing at the very first method stop_ABC_services by giving the following error: Error occured in stop_ABC_services - can't convert false into String.
Cannot proceed further. Quitting...
I am not able to figure out the solution for this. Appreciate the guidance to fix this.
Thanks
puts e.backtraceto it and post full error message please.while exec("#{ABC_service_cnt } >& ABC.log").to_i > 0exec, in accordance with the Unix system call of the same name, replaces the current process; it doesn't spawn a new one. This probably isn't what you want.execand the quotes, use the `<command> ` syntax. It's that button above the ~. I thinkexecends the process after it executes that command.