Created
August 29, 2012 13:56
-
-
Save rockpapergoat/3512916 to your computer and use it in GitHub Desktop.
crude command runner
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
#!/usr/bin/env ruby | |
=begin | |
reads contents of a file hosted on a web server, then executes the commands. | |
security holes? yes, probably... | |
=end | |
require 'open-uri' | |
def get_iface | |
@iface = %x(/usr/local/bin/active_net_service.sh).chomp | |
return @iface | |
end | |
def get_ip | |
iface = get_iface | |
@ip =`/usr/sbin/networksetup -getinfo #{iface} | awk '/^IP address:/ {print $NF}'`.chomp | |
return @ip | |
end | |
def check_empty | |
iface = get_iface | |
while iface.empty? | |
puts "no interface is active. waiting for a few seconds." | |
#%x(logger -t startup "no interface is active.") | |
sleep(10) | |
iface = get_iface | |
end | |
end | |
def match_ip | |
ip = get_ip | |
if ip.match(/^169.*/) | |
message = "stop right there. you have a self assigned IP." | |
puts message | |
%x(logger -t startup #{message}) | |
exit(1) | |
else | |
if ip.match(/\b(?:\d{1,3}\.){3}\d{1,3}\b/) | |
puts "you have: #{ip}" | |
%x(logger -t startup "running startup script...") | |
open("http://company.com/start.sh") {|f| | |
f.each_line {|line| system(line.chomp)} | |
} | |
%x(logger -t startup "finished startup script.") | |
exit(0) | |
end | |
end | |
end | |
check_empty | |
match_ip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment