Created
July 3, 2017 20:15
-
-
Save anonymous/830584f1cc48af018c281696a674f9e1 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' | |
# get arguments from command line | |
# decide what to do with them | |
# and verify they are legit commands | |
hostname = ARGV[0] | |
lock = ARGV[1] | |
user = ARGV[2] | |
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