Skip to content

Instantly share code, notes, and snippets.

@simnv
simnv / cisco_uptime_minutes.sh
Created August 11, 2016 07:11
convert cisco uptime line from "show version" command to minutes
# convert cisco uptime line to minutes
echo 'switch1 uptime is 2 years, 15 weeks, 2 days, 16 hours, 56 minutes' | python -c "import re,sys;[sys.stdout.write(re.sub(r' .*', '', line).rstrip() + '\t' + str(reduce(lambda x,y: x+y, [[1, 60, 24*60, 7*24*60, 365*24*60][i]*int(x) for i,x in enumerate(re.sub(r'[^0-9,]', '', re.sub(r'^.* uptime is ', '', line)).split(',')[::-1])])) + '\n') for line in sys.stdin]"
# switch1 1206296
echo 'switch1 uptime is 1 hour, 56 minutes' | python -c "import re,sys;[sys.stdout.write(re.sub(r' .*', '', line).rstrip() + '\t' + str(reduce(lambda x,y: x+y, [[1, 60, 24*60, 7*24*60, 365*24*60][i]*int(x) for i,x in enumerate(re.sub(r'[^0-9,]', '', re.sub(r'^.* uptime is ', '', line)).split(',')[::-1])])) + '\n') for line in sys.stdin]"
# switch1 116

Keybase proof

I hereby claim:

  • I am simnv on github.
  • I am simonov (https://keybase.io/simonov) on keybase.
  • I have a public key whose fingerprint is 0462 7ADC 4FE9 5C1C EA20 8714 AEFA C816 D87C D168

To claim this, I am signing this object: