From 0b8570e725295fd3caf37a8d8afc83eba19cd016 Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Mon, 17 Jan 2022 15:49:15 +0300 Subject: [PATCH] [~] Refactor --- dotfiles/.local/bin/commands | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/dotfiles/.local/bin/commands b/dotfiles/.local/bin/commands index 85ea2ab..d1ba63e 100755 --- a/dotfiles/.local/bin/commands +++ b/dotfiles/.local/bin/commands @@ -232,6 +232,28 @@ def eternal_firefox( if debug: assert subprocess.check_call(['notify-send', '%s:Closed' % group_name]) == 0 +def resilient_ethernet(ip_addr, ethernet_device): + subprocess.check_call( + r''' + sudo sh -c '\ +while true; \ +do ping -c 3 -w 3 -W 1 {{IP_ADDR}} || (\ + ip link set {{ETHERNET_DEVICE}} down; \ + ip link set {{ETHERNET_DEVICE}} up; \ + sleep 4; true;\ +); \ +sleep 10; clear; date; \ +done' + '''.replace( + '{{IP_ADDR}}', + ip_addr + ).replace( + '{{ETHERNET_DEVICE}}}', + ethernet_device + ), + shell=True + ) + def status(): return ' | '.join([ subprocess.check_output(o, shell=True).decode('utf-8').strip() @@ -322,6 +344,11 @@ try: debug=json.loads(sys.argv[5]), tabs=sys.argv[6:], ) + elif sys.argv[1] == 'resilient-ethernet': + resilient_ethernet( + ip_addr=sys.argv[2], + ethernet_device=sys.argv[3], + ) else: raise NotImplementedError except: