Permalink
Browse files

Sleep after killing dhcpcd

  • Loading branch information...
1 parent b96f184 commit 08f3a93bdde334d061f9ef0995696d35fcf84ca3 @rking rking committed with rking@sharpsaw.org Mar 2, 2013
Showing with 8 additions and 3 deletions.
  1. +8 −3 bin/,cat5
View
@@ -1,5 +1,5 @@
#!/usr/bin/env ruby
-## The opposite of ,wifi - for when it's connected to wlan0 but you want eth0
+## The opposite of ,wifi - for when it's connected to wlan0 but you want eth0 #encoding: utf-8
DHCPD = 'dhcpcd'
def verbose_system *cmd
@@ -12,8 +12,13 @@ def interface_match pat
lines.map{|e| e[/^\d+:\s+(#{pat}\d+)/] && $1}.compact
end
-verbose_system 'sudo', 'killall', DHCPD
-interface_match('wlan').each{|e| verbose_system 'sudo', 'ifconfig', e, 'down'}
cat5 = interface_match('eth').first
+begin
+ verbose_system 'sudo', DHCPD, cat5, '-x'
+ sleep 2 # dhcpcd takes a bit to shutdown
+rescue => e
+ warn "#{e} — continuing anyway"
+end
+interface_match('wlan').each{|e| verbose_system 'sudo', 'ifconfig', e, 'down'}
verbose_system 'sudo', DHCPD, cat5
verbose_system *%w(ping a.de -c 1)

0 comments on commit 08f3a93

Please sign in to comment.