Jojo John
Jojo John

Reputation: 400

Execute a linux command using ruby for getting hostname

I am new to ruby .

I have to write def , which returns the value by executing the command 'hostname -f' in a linux server. Please help me to solve this

Upvotes: 0

Views: 216

Answers (1)

SteveTurczyn
SteveTurczyn

Reputation: 36860

You can call the command within backticks. Use the chomp method to remove any trailing newline.

def get_host
  `hostname -f`.chomp
end

Upvotes: 1

Related Questions