{"id":933,"date":"2012-06-25T01:04:56","date_gmt":"2012-06-25T06:04:56","guid":{"rendered":"http:\/\/yourLinuxGuy.com\/?p=933"},"modified":"2012-06-25T02:57:18","modified_gmt":"2012-06-25T07:57:18","slug":"how-to-drop-your-ip-address-into-a-share","status":"publish","type":"post","link":"https:\/\/yourLinuxGuy.com\/?p=933","title":{"rendered":"How to drop your IP address into a share&#8230;"},"content":{"rendered":"<p>I have an Opensuse 12.1 workstation that I use as a script &#8220;toolbox&#8221;,\u00a0 out in the regular cubicle space where I work.\u00a0 Because it sits smack-dab in the middle of a DHCP-based environment &#8212; and the corporate policy is to block all out-going SMTP\/email &#8212; I can&#8217;t just email myself the IP Address like I might in other locations.\u00a0 However, I do need to know when it reboots (power outages, etc.) and potentially grabs a new IP address.<\/p>\n<p>In this case, the one thing that I *do* have access to is a Windows server share (this is a corporation, after all), so why not drop the IP address there&#8230;?\u00a0 To do this, I&#8217;ve written a quick little script to mount the share at boot, and dump the address to a text file on the share&#8230;.<\/p>\n<p>&#8230;But, I need to take an aside here.<\/p>\n<p>While I would normally just add a scripted call to the &#8220;<code>\/etc\/rc2.d\/after.local<\/code>&#8220;, something about <code>systemd<\/code> and the latest Opensuse 12.1 has caused this to stop working correctly.\u00a0 The good news is that <a href=\"http:\/\/forums.opensuse.org\/members\/jdmcdaniel3.html\">jdmcdaniel3<\/a> has put together some quick steps to fix that for you, and <a title=\"http:\/\/forums.opensuse.org\/blogs\/jdmcdaniel3\/systemd-using-after-local-script-opensuse-12-1-71\/\" href=\"http:\/\/forums.opensuse.org\/blogs\/jdmcdaniel3\/systemd-using-after-local-script-opensuse-12-1-71\/\" target=\"_blank\">you can find it all here on the Opensuse forum<\/a>.\u00a0 For the rest of this post, I&#8217;ll assume you&#8217;ve followed his steps and fixed it on 12.1, or you are using an earlier version where the after.local just works.<\/p>\n<p>First, create the script that will run at boot (after a delay), mount the share, and plop in a file with the address:<\/p>\n<p><code>vi \/home\/jpavlov\/IpAddress.bash<\/code><\/p>\n<pre>#!\/bin\/bash\r\n# Better wait for network...\r\nsleep 60\r\n# What time is it!\r\nRightNow=`date +%Y%m%d%H%M`\r\n# What file to write results?\r\nOutFile=\"$HOSTNAME-IpAddress.wri\"\r\n# Check the status of the mount first...\r\nMountResult=`mount|grep \"cifs\"`\r\nif [ \"XX$MountResult\" == \"XX\" ]; then\r\n  mkdir \/media\/cifs\r\n  # Mount the corporate share, mine is DFS-based...  set it to your path\r\n  mount -t cifs -o username=YourDomain\/YourUsername,password=YourPassword \/\/YourDomain\/DfsParent\/DfsPath1\/DfsPath2\/ \/media\/cifs\r\nfi\r\n# Switch to my work-group user sub-folder, again, set to taste and escape spaces\r\ncd \/media\/cifs\/User\\ Folders\/User\\ -\\ Jeremy\/linuxtoolbox\/\r\n# Finally, what we are waiting for\r\necho \"Results from $0 on $RightNow\" > $OutFile\r\n\/sbin\/ifconfig eth0|grep \"inet addr\"|sed s\/\"inet addr:\"\/\/g|awk '{ print $1 }' >> $OutFile\r\n# And I may as well drop an info message in case it doesn't work\r\necho \"$RightNow ifconfig export sccript done!\" >> \/var\/log\/messages\r\n<\/pre>\n<p>&#8230;And protect that file (and the password) from prying eyes with:<\/p>\n<p><code>chmod 700 \/home\/jpavlov\/IpAddress.bash<\/code><\/p>\n<p>Now, we need to add it to the <code>after.local<\/code> so it will launch at boot:<\/p>\n<p><code>echo \"\/home\/jpavlov\/IpAddress.bash\" &gt;&gt; \/etc\/rc.d\/after.local<\/code><\/p>\n<p>&#8230;And that&#8217;s about it.\u00a0 After a reboot, you should find something like <code>HOSTNAME-IpAddress.wri<\/code> in your folder, with the IP address from your workstation at last boot.\u00a0 Of course, you probably won&#8217;t do this is you have other folks who have root access to this machine, or they&#8217;d see your password in the script.\u00a0 Or you could create a drop-box type share that permits the deposit of the file, etc&#8230;<\/p>\n<p>Now go play!<br \/>\n\ud83d\ude09<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have an Opensuse 12.1 workstation that I use as a script &#8220;toolbox&#8221;,\u00a0 out in the regular cubicle space where I work.\u00a0 Because it sits smack-dab in the middle of a DHCP-based environment &#8212; and the corporate policy is to&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/yourLinuxGuy.com\/?p=933\">Read more<\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11,111],"tags":[],"class_list":["post-933","post","type-post","status-publish","format-standard","hentry","category-intermediate","category-opensuse12-1"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pnjn1-f3","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts\/933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=933"}],"version-history":[{"count":7,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts\/933\/revisions"}],"predecessor-version":[{"id":935,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts\/933\/revisions\/935"}],"wp:attachment":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}