-
-
Save toddnestor/a70a92db54c87474ab6d24a1bbb5576f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/ssh' | |
require 'optparse' | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "Usage: ruby permission.rb [-h some-host-option -a lock -u garion]" | |
%i{host user action}.each do |option| | |
opts.on("-#{option[0]}VALUE", "--#{option}=VALUE") do |value| | |
options[option] = value | |
end | |
end | |
end.parse! | |
# get arguments from command line | |
# decide what to do with them | |
# and verify they are legit commands | |
hostname = options[:host] | |
lock = options[:action] | |
user = options[:user] | |
case lock | |
when "lock" | |
cmd = "sudo chsh -s /usr/bin/false #{user}" | |
locker(hostname, cmd) | |
when "unlock" | |
cmd = "sudo chsh -s /bin/bash #{user}" | |
locker(hostname, cmd) | |
else quit | |
end | |
def locker(host, cmd) | |
begin | |
ssh = Net::SSH.start(host) | |
res = ssh.exec!(cmd) | |
ssh.close | |
puts res | |
rescue | |
puts "Unable to connect to #{@hostname}!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment