<?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>DaveOnCode &#187; mac</title>
	<atom:link href="http://www.daveoncode.com/category/mac/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.daveoncode.com</link>
	<description>Objective C, iOS and more programming stuff</description>
	<lastBuildDate>Mon, 19 Dec 2011 12:11:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Learning shell scripting while trying to fix Snow Leopard local network issue :)</title>
		<link>http://www.daveoncode.com/2010/04/08/learning-shell-scripting-while-trying-to-fix-snow-leopard-local-network-issue/</link>
		<comments>http://www.daveoncode.com/2010/04/08/learning-shell-scripting-while-trying-to-fix-snow-leopard-local-network-issue/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 15:31:44 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[samba]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[smb]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=606</guid>
		<description><![CDATA[Mac OS X is a great system, but this doesn&#8217;t mean it&#8217;s perfect and without issues. One thing is not working as it would (in Snow Leopard 10.6.X), it&#8217;s the automatic discovering and mounting of local machines connected to the same network. This is especially true if the network includes a lot of Windows computers. [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.daveoncode.com/2010/04/08/learning-shell-scripting-while-trying-to-fix-snow-leopard-local-network-issue/' addthis:title='Learning shell scripting while trying to fix Snow Leopard local network issue :) ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Mac OS X is a great system, but this doesn&#8217;t mean it&#8217;s perfect and without issues. One thing is not working as it would (in Snow Leopard 10.6.X), it&#8217;s the automatic discovering and mounting of local machines connected to the same network. This is especially true if the network includes a lot of Windows computers. Theoretically those machines should be automatically discovered and displayed in Finder under &#8220;SHARED&#8221; label, but often this is not the case. Anyway in such cases is fortunately possible to connect to a particular device from Finder (once we know its IP address) by choosing &#8220;Connect to server&#8230;&#8221; (cmd+K) and by using the Samba protocol (ie: smb://ip-address). This is however very annoying, because we have to know each ip we want to connect to and type several addresses, so I spent some time to find a way to make this process automatic (because I didn&#8217;t find a solution to the original OS X issue) and I realized a shell script which tries to do the job the Leopard should do :)<br />
I&#8217;m really a newbie when it comes to shell scripting (and networking too :P) and my script doesn&#8217;t work perfectly, anyway it does an acceptable work the most of times and although it doesn&#8217;t really solve the problem, it could help a lot.<br />
The script is the following:</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<br />
<span style="color: #666666; font-style: italic;"># get user name</span><br />
<span style="color: #7a0874; font-weight: bold;">declare</span> <span style="color: #007800;">currentuser</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">whoami</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># get mac name</span><br />
<span style="color: #7a0874; font-weight: bold;">declare</span> <span style="color: #007800;">macname</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>scutil <span style="color: #660033;">--get</span> ComputerName<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># save arp command result</span><br />
<span style="color: #7a0874; font-weight: bold;">declare</span> <span style="color: #007800;">ipstring</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>arp -a<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># split ipstring into an array by using a regex to match ip addresses</span><br />
<span style="color: #7a0874; font-weight: bold;">declare</span> <span style="color: #660033;">-a</span> <span style="color: #007800;">iplist</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$ipstring</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-o</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">&quot;([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># display addresses found</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${#iplist[*]}</span> ip addresses found&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># switch directory to user dir</span><br />
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$currentuser</span><br />
<br />
<span style="color: #666666; font-style: italic;"># for each ip in list try to mount it using smbfs</span><br />
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">ip</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${iplist[@]}</span> <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">do</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> link-to-<span style="color: #007800;">$ip</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;creating directory link-to-<span style="color: #007800;">$ip</span> under /Users/<span style="color: #007800;">$currentuser</span>&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mkdir</span> link-to-<span style="color: #007800;">$ip</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;trying to mount //<span style="color: #007800;">$macname</span>:@<span style="color: #007800;">$ip</span>/Public&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-t</span> smbfs <span style="color: #000000; font-weight: bold;">//</span><span style="color: #007800;">$macname</span>:<span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$ip</span><span style="color: #000000; font-weight: bold;">/</span>Public <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$currentuser</span><span style="color: #000000; font-weight: bold;">/</span>link-to-<span style="color: #007800;">$ip</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'folder &quot;link-to-$ip&quot; already exists... skip'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span> <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">done</span><br />
<br />
<span style="color: #666666; font-style: italic;"># complete</span><br />
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></div></td></tr></tbody></table></div>
<p>Any comment and suggestion is really appreciated! Thanks</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.daveoncode.com/2010/04/08/learning-shell-scripting-while-trying-to-fix-snow-leopard-local-network-issue/' addthis:title='Learning shell scripting while trying to fix Snow Leopard local network issue :) ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2010/04/08/learning-shell-scripting-while-trying-to-fix-snow-leopard-local-network-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

