Reputation: 24267
Why would net-ssh not be able to execute the useradd
command?
This is my net-ssh code:
Net::SSH.start(host, user, forward_agent: true) do |ssh|
ssh.open_channel do |ch|
ch.request_pty
ch.exec "mkdir /tmp/unicorn"
ch.exec "sudo groupadd unicorn"
ch.exec "sudo chgrp unicorn /tmp/unicorn"
ch.exec "sudo useradd application" do |ch, success|
if success
puts 'command worked'
else
puts 'command failed'
end
end
end
end
All of the commands work except for the useradd
command. I can log in and run the useradd
command and a user is added.
Thanks, Eric
Upvotes: 0
Views: 153
Reputation: 4396
I would modify your script to add the command
puts ch.exec "sudo which useradd"
To see if it is a path problem.
I would also add
ch.exec 'sudo useradd application 1>/tmp/useradd.log 2>&1'
And then go look on the target box to see if there were any errors logged in the /tmp/useradd.log
file.
Upvotes: 1