Posts tagged with shell

Migrating from tcsh to bash

My move to Linux in the workplace almost necessarily entails a shell change. I’ve been using tcsh for years, going back to the days before bash added tab completion, if memory serves, but in the last year or so, I’ve been considering a switch to bash for several reasons:

  1. It’s the default shell on the Mac and most CLI help articles reference bash.
  2. Every Unix variant I can think of seems to ship with bash as the default shell.
  3. Some Unix variants don’t even bother to ship with tcsh.

Ubuntu, my distro of choice, is one of those variants that doesn’t ship with tcsh. Yeah, I know I can install tcsh easily enough, but that seems like a recipe for repetition over time as I work on new machines running other distros that may or may not include a tcsh install. For the sake of universal access, I think I’d rather just conform.

This past weekend I began the process of migrating my well-worn, painstakingly accumulated .tcshrc login script to its bash counterpart, .bash_profile. What I’m finding is that it’s not all that simple.

Continue Reading »

Dynamic DNS Updates

Okay, so my OpenDNS configuration wasn’t perfect. OpenDNS liked it just fine, but DynDNS was another story. They tagged me as an abuser and blocked my host name. Oops.

When I built my script using cURL to call the DNS-O-Matic API, I didn’t build in any intelligence. I created a cron job that ran every half hour and call my script. The script simply passed my current IP address to DNS-O-Matic who, in turn, passed it to DynDNS. My approach was the obvious one and at the same time, a bit brutish. If nothing has changed, then no harm, no foul…right?

Understandably, DynDNS didn’t think so. They consider it abuse if their system is getting pinged too often without a change actually being made. By those rules, I was most definitely playing the role of abuser. Today I made a few changes to my script so that it’s a bit more intelligent, while maintaining a degree of simplicity. I also added some output so I could track what was happening if I ever need to do so.

 touch updatedns.log

 echo “”
 echo “========================= `date` =====================”
 echo “”

 # 
 # If a file named updatedns.current doesn’t exist, then retrieve
 # the current network IP address and write it to that file.  Then
 # set the $lastip value to something that we know won’t match.
 # 
 # If the file does exist, then read its contents into the value of 
 # $lastip.
 # 
 if [ ! -e “updatedns.current” ]; then
   echo “updatedns.current does not exist.”
   curl -s -m 60 http://myip.dnsomatic.com/ > updatedns.current
   echo “updatedns.current created.”

   lastip=“UNKNOWN”
 else
   lastip=`cat updatedns.current`
 fi

 # 
 # Retrieve the network IP as it exists right this moment.
 # 
 currentip=`curl -s -m 60 http://myip.dnsomatic.com/`

 echo “Last known IP was $lastip.”
 echo “Current IP verified as $currentip.”

 # 
 # If the last and current IPs are different, then tell
 # DNS-O-Matic to broadcast an update.
 # 
 if [ “$currentip” != “$lastip” ]; then
   echo “$currentip != $lastip.  Updating DNS-O-Matic.”
   curl -m 60 -k -u myusername:mycrazystrongpassword \
        https://updates.dnsomatic.com/nic/update
        ?hostname=all.dnsomatic.com&myip=$ip
        &wildcard=NOCHG&mx=NOCHG&backmx=NOCHG
   echo $currentip > updatedns.current
 else
   echo “IP address has not changed. No action was taken.”
 fi

 exit 0

Note that the URI in the curl statement must be on one line. It’s split here due to space limitations. And the cron job? It looks like this:

*/5 * * * * /usr/local/bin/updatedns.sh >> /usr/local/bin/updatedns.log

Since I’m now determining whether an update needs to be done, I’m running the script every 5 minutes instead of every half hour. Might as well have less lag time when an update is needed, right?

Configuring OpenDNS for a Complex Network

For a while now, I’ve been monkeying about with using OpenDNS as my DNS service provider rather than rather than using my ISP‘s name servers in order to take advantage of some of the great additional features offered by OpenDNS. In a simple scenario, configuring OpenDNS name server support is easy – just tell your network or machine to use their name servers and go on about your day. Easy. Except that my network architecture isn’t that simple. The other night I decided to put in the time to get myself sorted out and commit to OpenDNS.

In a nutshell, here’s what my home network architecture and usage looks like:

  • I connect to the internet via DSL service.
  • I do not have a static IP. It would make life easier (see problem #3 below), but I’m not willing to pay the premium.
  • Behind a couple of firewalls, I run a LAN.
  • I have an internal name server for resolving the IP addresses of other machines on the LAN.
  • I have a DHCP server that broadcasts the name servers to be used by the other machines on the LAN in addition to assigning their IP addresses.
  • I have an account with DynDNS that allows me to connect to my home network by name even though it has a dynamic IP that changes with some frequency.
  • I often have to connect to work through a VPN to access corporate resources.

In the course of configuring OpenDNS for use in my environment, I bumped into a number of problems that I needed to solve.

Continue Reading »

Trying SmartSVN Again

Although I’ve been here before, I decided to give SmartSVN another try. It’s the only one I wasn’t able to actually play with because I wasn’t even able to get it open. This time, though, I put in a little effort.

Instead of just downloading the application and assuming it would, or should, work, I decided to be sure I met the system requirements. The only requirement, as far as I can tell is a JRE of version 1.4.1 or higher.

$java -version java version "1.5.0_13" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05-237) Java HotSpot(TM) Client VM (build 1.5.0_13-119, mixed mode, sharing)

Requirement met…check. Application downloaded…check. Tarball extracted…check. Application opened…denied (supply your own sound effect, please).

Clearly others use this application. Some, probably, with great success and affection. Why can’t I? The only way I can get it to start is to Show Package Contents and then navigate to Contents > Resources > Java and double click smartsvn.jar. Argh. I can’t believe there’s not a better way.

I’m not even sure that opening the app that way offers full functionality. For example, I can’t find a way to simply connect to a repository and browse its content. I have to create some kind of project first. Even worse, I have to do so by connecting to an existing working directory or by checking out code from one of my existing repositories. At the moment, I want to do neither. I just want to connect and perform a little maintenance directly on the repository.

I guess it’s me and my command line for at least a little longer.

Deleting .svn Folders

From time to time, I find myself looking at a directory full of .svn folders that I need to delete for one reason or another. On the Mac it’s not really a problem. I’m reasonably well-versed in the art of the Shell, so it was a trivial matter to pass the results of a find through to rm:

rm -rf `find . -type d -name .svn`

On Windows, though, I’m not so well-versed. DOS isn’t the easiest beast to tame and I (quite intentionally) haven’t written a batch script in years. As an avid Cygwin user, I can just crack open a shell and use the syntax above, but I’m also a user of TortoiseSVN and tend to spend more time in Windows Explorer than I do in Cygwin. As such, I found the idea of having a Windows Explorer context menu option appealing. A little hunting and pecking turned up a bit of code that, with a little modification, does exactly what I need it to do.

For anyone that may also be interested:

  1. Copy the code below and paste it into your favorite text editor.
  2. Save the file as whatever-you-want.reg (the .reg is the important part).
  3. Double-click the .reg file you just created.
  4. Confirm that you want to update your registry.

It goes without saying, of course, that all of the usual registry backup admonitions apply here. Monkeying about in the registry can be dangerous.

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN]
@="Delete SVN Folders"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN\command]
@="cmd.exe /c \"TITLE Removing SVN Folders in %1 && COLOR 9A && 
FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" \""

Update 2/20/2008: When I published this, I neglected to include a screenshot to provide some visualization of how the context menu option is presented. A few folks have asked for it, so the image shown below is a cropped image highlighting the relevant section. For a complete look at my context menu, click the image. Windows Explorer context menu snippet

Notes:

  • The last line should be edited to be on a single line. It was split for legibility.
  • I’m running Windows XP. The first line may need to be changed for other Windows versions.

For what it’s worth, the OS X solution above can easily be adapted to a Finder context menu by employing Automator. I don’t spend much time in Finder so I haven’t bothered, but I have a number of other scripts that I’ve added to the Finder context menu.