<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Michael Jay Lissner</title><link href="https://michaeljaylissner.com/" rel="alternate"></link><link href="https://michaeljaylissner.com/feeds/tag/script" rel="self"></link><id>https://michaeljaylissner.com/</id><updated>2009-02-19T20:45:10-08:00</updated><entry><title>Location Based DNS Switching For Internet vs. Intranet</title><link href="https://michaeljaylissner.com/posts/2009/02/19/location-based-dns-switching-for-intranet-vs-internet/" rel="alternate"></link><updated>2009-02-19T20:45:10-08:00</updated><author><name>Mike Lissner</name></author><id>tag:michaeljaylissner.com,2009-02-19:posts/2009/02/19/location-based-dns-switching-for-intranet-vs-internet/</id><summary type="html">&lt;p&gt;I realized over the weekend that since I run my own mail server out of my 
home, I can configure my computer to download my mail over the intranet 
whenever I am on my home network. By doing this, I can drastically reduce my
mail download times because it cuts the Internet out of the equation. Rather
than using &lt;span class="caps"&gt;DNS&lt;/span&gt; + the Internet to get my mail, I can download it directly 
from internal &lt;span class="caps"&gt;IP&lt;/span&gt; address of the&amp;nbsp;server. &lt;/p&gt;
&lt;p&gt;To understand how to set this up, you have to understand that whenever you 
use a domain name (like michaeljaylissner.com), your computer does an &lt;span class="caps"&gt;IP&lt;/span&gt; 
lookup. First, it looks in /etc/hosts to see if it knows the &lt;span class="caps"&gt;IP&lt;/span&gt; of the 
domain locally. If it does, it will use the &lt;span class="caps"&gt;IP&lt;/span&gt; listed there. If it does 
not, it will ask your Internet provider what &lt;span class="caps"&gt;IP&lt;/span&gt; to use, 
and will use that. Thus, what we want to do is set up the computer so that 
when we are at home, /etc/hosts provides the internal &lt;span class="caps"&gt;IP&lt;/span&gt; of our server, 
and so when we are not at home, it does&amp;nbsp;not.&lt;/p&gt;
&lt;p&gt;When I am at home, I am always on a wireless network called, 
&lt;code&gt;pizzapuppysantaclaus&lt;/code&gt;. Thus, by checking what wireless network I am 
connected to, I can check if I am at home, and make whatever changes are 
necessary. Conveniently, whenever you change network connections, 
you run all of the scripts located in &lt;code&gt;/etc/network/if-up.d/&lt;/code&gt;. Thus, 
we will put a small script in there that checks what wireless network we are
 on, and then changes our /etc/hosts file if&amp;nbsp;necessary.&lt;/p&gt;
&lt;p&gt;To set up this configuration, I made three files. The first is the script 
mentioned above, which needs to be owned by root, 
and placed in &lt;code&gt;/etc/network/if-up.d&lt;/code&gt;. You can name it whatever you want, 
and by changing &lt;code&gt;pizzapuppysantaclaus&lt;/code&gt; to the name of your network, 
you can fit it to your needs. Here&amp;#8217;s the contents of the&amp;nbsp;script:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="c"&gt;#First, we check if we are connected to pizzapuppysantaclaus&lt;/span&gt;

&lt;span class="c"&gt;#If grep has a hit, we&amp;#39;re connected, and $? will equal 0, if not, $? will equal 1&lt;/span&gt;
iwconfig 2&amp;gt; /dev/null | grep pizzapuppysantaclaus &amp;gt; /dev/null

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 0 &lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="c"&gt;#Switch the /etc/hosts file with the other one&lt;/span&gt;
  cp -f /etc/hostsIntranet /etc/hosts

  &lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="c"&gt;#Switch the /etc/hosts file with the other one&lt;/span&gt;
  cp -f /etc/hostsInternet /etc/hosts

&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="nb"&gt;exit &lt;/span&gt;0
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This script simply performs a check of our wireless &lt;span class="caps"&gt;ID&lt;/span&gt;. If it&amp;#8217;s 
&lt;code&gt;pizzapuppysantaclaus&lt;/code&gt;, it switches &lt;code&gt;/etc/hostsIntranet&lt;/code&gt; for &lt;code&gt;/etc/hosts&lt;/code&gt;. If 
not, it switches &lt;code&gt;/etc/hostsInternet&lt;/code&gt; for &lt;code&gt;/etc/hosts&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The contents of &lt;code&gt;/etc/hostsIntranet&lt;/code&gt; are:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;192.168.1.132   michaeljaylissner.com
192.168.1.132   charityhikers.org
127.0.0.1   localhost
127.0.1.1   opal

&lt;span class="c"&gt;# The following lines are desirable for IPv6 capable hosts&lt;/span&gt;
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;And &lt;code&gt;/etc/hostsInternet&lt;/code&gt; is just a copy of &lt;code&gt;/etc/hosts&lt;/code&gt;. &lt;/p&gt;
&lt;p&gt;So, to make this whole thing run, put the script in &lt;code&gt;/etc/network/if-up.d&lt;/code&gt;, 
and set its owner to root with execute permission. Create a file called 
&lt;code&gt;/etc/hostsIntranet&lt;/code&gt;, that contains your intranet configuration, 
as shown above. Make a copy of your normal &lt;code&gt;/etc/hosts&lt;/code&gt; file called 
&lt;code&gt;/etc/hostsInternet&lt;/code&gt;. &lt;/p&gt;
&lt;p&gt;Once all that&amp;#8217;s done, you should be all set. Any questions, 
please feel free to&amp;nbsp;comment!&lt;/p&gt;</summary><category term="script"></category><category term="project"></category><category term="/etc/hosts"></category><category term="networking"></category><category term="DNS"></category></entry><entry><title>A Script to Kill Evolution</title><link href="https://michaeljaylissner.com/posts/2008/10/13/a-script-to-kill-evolution/" rel="alternate"></link><updated>2008-10-13T17:36:05-07:00</updated><author><name>Mike Lissner</name></author><id>tag:michaeljaylissner.com,2008-10-13:posts/2008/10/13/a-script-to-kill-evolution/</id><summary type="html">&lt;p&gt;I use Evolution as my mail reader, and I like it. It has a lot of good features including a calendar, address book, memos and mail, as well as a number of others. One problem though is that it gets caught up when processing mail, and sometimes just won&amp;#8217;t come&amp;nbsp;back.&lt;/p&gt;
&lt;p&gt;The other problem is that it has several helper apps that are behind the scenes making things work properly, so if you try to just kill the application itself, those will still be running and your problem may not be&amp;nbsp;solved.&lt;/p&gt;
&lt;p&gt;My solution was to write a short script to kill all of Evolution and its helper apps. Hope this helps somebody else&amp;nbsp;someday:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;% more bin/evokill 
&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

ps aux | grep evolution
&lt;span class="nb"&gt;kill&lt;/span&gt; &lt;span class="sb"&gt;`&lt;/span&gt;ps aux | grep evolution | awk -F&lt;span class="s1"&gt;&amp;#39; &amp;#39;&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;{print $2}&amp;#39;&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This script just looks for any application that has the word evolution in its name, and then sends it the kill signal. Not too sophisticated, but it gets the job done. You could easily substitute the word evolution for something else as&amp;nbsp;well.&lt;/p&gt;</summary><category term="Evolution"></category><category term="Bash"></category><category term="Script"></category></entry><entry><title>Delete Original Images from F-Spot and Rotate Using Exif Information</title><link href="https://michaeljaylissner.com/posts/2008/09/15/delete-original-images-from-f-spot-and-rotate-using-exif-information/" rel="alternate"></link><updated>2008-09-15T23:33:48-07:00</updated><author><name>Mike Lissner</name></author><id>tag:michaeljaylissner.com,2008-09-15:posts/2008/09/15/delete-original-images-from-f-spot-and-rotate-using-exif-information/</id><summary type="html">&lt;p&gt;Over the past couple weeks, my girlfriend and I spent a lot of time working on the photos from our Peru trip. Since we used F-Spot to do our photo editing, when we were done we had a couple of problems when it came to transferring the photos back to her computer which is running&amp;nbsp;Vista. &lt;/p&gt;
&lt;p&gt;The first problem was that when we rotated images with F-Spot, it simply changed the exif information for the photo, and didn&amp;#8217;t change the pixels of the photo themselves. This was fine when viewed in F-Spot because it is aware of exif information, and displays the photos correctly. However, when we transferred the files to her computer, we discovered that Vista does not take exif information into account on the &lt;span class="caps"&gt;OS&lt;/span&gt; level, nor does Picassa. As a result, we needed to somehow rotate the images that had exif information indicating a non-normal&amp;nbsp;rotation.&lt;/p&gt;
&lt;p&gt;The second problem we encountered is that in F-Spot when you edit a photo, it creates a second file with the edited photo, and leaves the original unchanged. So, if you edit file dsc00343.jpg, you get a second photo called dsc00343 (Modified).jpg. This is &lt;span class="caps"&gt;OK&lt;/span&gt; when in F-Spot, however, when we went to her computer, it was very hard for her to have &lt;span class="caps"&gt;ONLY&lt;/span&gt; the modified version of those photos, and to delete the originals (since the edited versions are better than the&amp;nbsp;originals).&lt;/p&gt;
&lt;p&gt;To solve the first problem, I used a couple of tricks. The first thing I did was to make a copy of the photos in case all went&amp;nbsp;south.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;mkdir backupPhotos
cp *.jpg *.jpeg backupPhotos
&lt;span class="nb"&gt;cd &lt;/span&gt;backupPhotos
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Once that is done, we can begin rotating images. For this, we will need the jhead&amp;nbsp;program.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;sudo aptitude install jhead
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Once that&amp;#8217;s installed, we&amp;nbsp;rotate:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;jhead -autorot  *.jpg *.jpeg
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This will rotate all of the files that have unusual information in the exif orientation&amp;nbsp;field. &lt;/p&gt;
&lt;p&gt;Problem number one&amp;nbsp;solved.&lt;/p&gt;
&lt;p&gt;For problem two, we will need to isolate all of the photos that have been modified, and delete the originals. To do this, we will capitalize on the fact that the renamed images use the original pictures name in their&amp;nbsp;name. &lt;/p&gt;
&lt;p&gt;To begin with, we create a list of the photos that have been&amp;nbsp;modified:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;ls *.jpg *.jpeg | grep -i modified &amp;gt; modifiedImages.txt
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Using awk, we can separate out the original name of the photos. The following 
commands will convert the &amp;#8216;)&amp;#8217; to &amp;#8216;(&amp;#8216; and will use the two &amp;#8216;(&amp;#8216; as a delimiters, 
returning the name of the file as the first field, and the .jpg or .jpeg as 
the third field. After that, it will remove any spaces from the file name, and 
will create a new file with a list of the modified pictures. It sounds 
complicated, but the final result should&amp;nbsp;work:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;tr &lt;span class="s1"&gt;&amp;#39;)&amp;#39;&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;(&amp;#39;&lt;/span&gt; &amp;amp;lt; modifiedImages.txt &amp;gt; modifiedImages2.txt
cat modifiedImages2.txt | awk -F&lt;span class="s1"&gt;&amp;#39;(&amp;#39;&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;{print $1,$3;}&amp;#39;&lt;/span&gt; | sed &lt;span class="s1"&gt;&amp;#39;s/  //g&amp;#39;&lt;/span&gt; &amp;amp;gt; modifiedImages3.txt
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You should now have a file called modifiedImages3.txt that contains the name of all of the original photos. To delete the pictures in this list from the collection - permanently -&amp;nbsp;run:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;rm &lt;span class="sb"&gt;`&lt;/span&gt;cat modifiedImages3.txt&lt;span class="sb"&gt;`&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You should now be able to transfer this entire directory of photos to another computer without rotation issues or duplicated&amp;nbsp;photos.&lt;/p&gt;</summary><category term="script"></category><category term="f-spot"></category><category term="awk"></category><category term="grep"></category></entry></feed>