<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Aaron&#039;s Worthless Words &#187; grep</title>
	<atom:link href="http://aconaway.com/tag/grep/feed/" rel="self" type="application/rss+xml" />
	<link>http://aconaway.com</link>
	<description>It&#039;s possible that someone somewhere needs to see this.</description>
	<lastBuildDate>Wed, 01 Feb 2012 02:07:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Using SSH to Run Commands on a Router or Switch</title>
		<link>http://aconaway.com/2009/04/30/using-ssh-to-run-commands-on-a-router-or-switch/</link>
		<comments>http://aconaway.com/2009/04/30/using-ssh-to-run-commands-on-a-router-or-switch/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 14:54:52 +0000</pubDate>
		<dc:creator>Aaron Conaway</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cisco]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[csm]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[privilege]]></category>
		<category><![CDATA[router]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[switch]]></category>

		<guid isPermaLink="false">http://aconaway.com/?p=322</guid>
		<description><![CDATA[SSH is more than just a shell.  You can copy files from and to a server or piece of network gear with it.  You can use it to tunnel traffic.  Possibly my favorite, though, is to use SSH to run a command on a remote box without interacting with a shell. One of my biggest pet peeves with IOS (or pretty much any Cisco OS) is the lack of complex filtering.  Let&#8217;s say I want to look at all the downed ports and interfaces on modules 3 and 6 of my 6509.  I can&#8217;t easily do that with command from the IOS, but, on my Linux box, I can use multiple grep commands to get exactly what I want really easily.  Let&#8217;s work through the example, shall we? To start with, let&#8217;s just do a show ip int brief without getting a shell on the switch. ssh my.switch.com "show ip int brief" When you run this and give your password, you see the output we&#8217;ve all learned to love, and, now that you&#8217;ve got it in STDOUT on your Linux box, you can start filtering. Now, let&#8217;s use grep to find the downed ports and interfaces on modules 3 and [...]]]></description>
			<content:encoded><![CDATA[<p>SSH is more than just a shell.  You can copy files from and to a server or piece of network gear with it.  You can use it to tunnel traffic.  Possibly my favorite, though, is to use SSH to run a command on a remote box without interacting with a shell.</p>
<p>One of my biggest pet peeves with IOS (or pretty much any Cisco OS) is the lack of complex filtering.  Let&#8217;s say I want to look at all the downed ports and interfaces on modules 3 and 6 of my 6509.  I can&#8217;t easily do that with command from the IOS, but, on my Linux box, I can use multiple <em>grep </em>commands to get exactly what I want really easily.  Let&#8217;s work through the example, shall we?</p>
<p>To start with, let&#8217;s just do a <em>show ip int brief</em> without getting a shell on the switch.</p>
<blockquote>
<pre>ssh my.switch.com "show ip int brief"</pre>
</blockquote>
<p>When you run this and give your password, you see the output we&#8217;ve all learned to love, and, now that you&#8217;ve got it in STDOUT on your Linux box, you can start filtering. Now, let&#8217;s use <em>grep </em>to find the downed ports and interfaces on modules 3 and 6.</p>
<blockquote>
<pre>ssh my.switch.com "show ip int brief" | grep down | grep Ethernet[36]</pre>
</blockquote>
<p>How about downed ports and interfaces on modules 3 and 6 that not administratively down?</p>
<blockquote>
<pre>ssh my.switch.com "show ip int brief" | grep down | grep Ethernet[36] | grep -v admin</pre>
</blockquote>
<p>I&#8217;ll stop there, but it can go on and on.  Read up on regular expression and/or grep if you don&#8217;t know what we&#8217;re doing here.</p>
<p>What&#8217;s really happening is that we&#8217;re taking the output of the command &#8220;ssh &#8230;.&#8221; and piping it (with |) to the command <em>grep</em>.  We can send it to whatever command we want, though, so don&#8217;t be shy.  I&#8217;ve actually written several scripts that take output of commands like <em>show int description</em> on a router to generate some reports.  When I want to run one of those, I do something like this.</p>
<blockquote>
<pre>ssh my.switch.com "show int desc" | parseOutput.pl</pre>
</blockquote>
<p>There&#8217;s always a gotcha or two to watch for, isn&#8217;t there?  I&#8217;ve found a couple.</p>
<p>First, your command runs at your privilege level, so, if your user is priv 1, you&#8217;re not going to be able to do a <em>show run</em> or <em>reload</em>.  You could just ignore security for a bit and set your privilege to 15, but I don&#8217;t recommend doing anything like that.  Before you say it, you&#8217;ll probably have a hard time with enabling as well.  You can only run one command at a time, so you would just enable yourself and get kicked off.  Not very helpful.</p>
<p>Another problem I see is the lack of public/private key pair support on Cisco devices.  On a Linux box, you can copy your keys around, and those are presented in lieu of a password.  Since (most) Cisco devices don&#8217;t have home directories, there&#8217;s no place to drop the keys, and we&#8217;re left with just using passwords.  Support for this would be nice, but the security problems associated with keep SSH keys and user home directories are probably too much to even think about.</p>
<p>What else?  Oh, yeah.  The PIX/FWSM/ASA family supports SSH, but it acts differently from the IOS guys.  When you run a command through SSH, you actually get an interactive shell with the command already on the CLI for you. This is probably by design; the only thing you can really do from a non-priv prompt is to <em>enable</em>.</p>
<p>Anyway, send any <span style="text-decoration: line-through;">grilling tips</span> questions my way.</p>
<div class="wp-about-author-containter-around" style="background-color:#ffffff;"><div class="wp-about-author-pic"><img alt='' src='http://1.gravatar.com/avatar/14352aa939196349e4b9f2a272ca5112?s=100&amp;d=&amp;r=G' class='avatar avatar-100 photo' height='100' width='100' /></div><div class="wp-about-author-text"><h3><a href='http://aconaway.com/author/jac/' title='Aaron Conaway'>Aaron Conaway</a></h3><p>I like to lean my head to the left, hit it with the palm of my right hand, and document what knowledge falls out.</p><p><a href='http://aconaway.com' title='Aaron Conaway'>Website</a> - <a href='http://aconaway.com/author/jac/' title='More posts by Aaron Conaway'>More Posts</a> </p></div></div>]]></content:encoded>
			<wfw:commentRss>http://aconaway.com/2009/04/30/using-ssh-to-run-commands-on-a-router-or-switch/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

