Tag Archives | OSX

Update DynDNS from the command line

My router is not updating DynDNS correctly, so I wanted to use a simple cron job to do the same. Here is a simple BASH/Shell script to update DynDNS:

IP=$(curl -s icanhazip.com)
curl -v -k -u username:password “https://members.dyndns.org/nic/update?hostname=DNSHOSTNAME.dyndns.org&myip=$IP”

Photos.app on my iPhone crashes, and Mac does not see any photos on my iPhone (iOS5)

Crap!!!! I had close to 400 pictures on my iPhone. I back it up all the time, but I had not “processed them” (my workflow is to use Image Capture.app to pull photos off of the iPhone, and into a folder, that I then import into iPhoto. I zip up (compress) the original folder containing the originals.)

Every time I opened the Photos app on my iPhone, it crashes. Every time, I look at previous photos from the Camera.app, I see a lot of “Black photos”. Something was screwed up. I figured I needed to import the photos into my workflow and start fresh.

I fired up “Image Capture.app” to pull the photos in, and it saw nothing. I started to get nervous, because I had Halloween photos on there.

All my photos were showing up in “Photo Stream”, but I wanted the originals (does Photo Stream copy the originals? Full quality? I did not know).

My Solution

I figured that since I backed up my iPhone in iTunes all the time, there should be a way to extract the photos from a backup.

If you have a valid backup that has your photos in it, and you have not encrypted your backups, then use iPhone Backup Extractor.app to restore the photos. Fire up the app, select read backups, and then select iOS files. The restore will put all your photos in “iOS Files/Media/DCIM/100APPLE/”

Hope that helps someone.

Cisco ASA and smart tunnels – my experience on OS X 10.7

I have been playing with smart tunnels on my Cisco ASA. The documentation is a little scarce on examples, so I thought I would post what I have found. On OS X, not much appears to work (I only tried with Safari). Maybe this post will help someone, or they will post a comment on how to get these apps working.

I was able to get terminal working, but my terminal preferences are ignored. Once Terminal was started, I could ssh into a server behind the ASA:

smart-tunnel list applist Terminal terminal platform mac

Remote Desktop
I was able to get Remote Desktop to launch, but I could not connect to a server behind the ASA. Not sure why:

smart-tunnel list smarttunlist-jbmurphy RemoteDesktop “/Applications/Remote Desktop Connection.app/Contents/MacOS/Remote Desktop Connection” platform mac

I could get Safari to start, but it would crash as soon as I tried to access a site behind the ASA.

smart-tunnel list smarttunlist-jbmurphy Safari /Applications/Safari.app/Contents/MacOS/Safari platform mac

The error thrown was described by @craigbox here. I also see this in the logs: sandbox: WebProcess(xxxxxx) deny file-write-data /private/tmp/narwhal.log I know that there is new “Sandboxing” with Lion, maybe that is the issue.

Anyway, not a lot of success, but maybe a discussion will follow. I will update if I have anymore luck.

VMware Fusion 4 – Did they move vmrun?

Did they move vmrun in VMware Fusion 4?

In version 4, I find it here: “/Applications/VMware Fusion.app/Contents/Library/”

But this documentation says that the command should be in “/Library/Application Support/VMware Fusion”, but I found it here”/Applications/VMware\ Fusion.app/Contents/Library/vmrun”

I don’t see anything in the release notes.



OS X: Running a script when a USB drive is inserted

I rsync all my data to a USB drive that I keep at work. I wanted a way to have my rsync script automatically run when I plugged in the drive – kinda like Time Machine.

It ended up being pretty simple. All I needed to do is create and AppleScript and attach it to a “Folder Action” for the /Volumes folder. This script below is launched when a new item is added to the /Volumes folder, i.e. when you insert a new volume. This script will try to run a BASH script if it exists on that volume (.OnInsert)

on adding folder items to this_folder after receiving these_items
	repeat with current_item in these_items
			do shell script POSIX path of current_item & ".OnInsert"
		end try
	end repeat
end adding folder items to

Save this as a .scpt file and put it in ~/Library/Workflows/Applications/Folder\ Actions folder.
Next, right click the /Volumes folder and select Services -> Folder Action Setup and attach the script you just created

Running a BASH script when my Laptop is opened at home – Part 2

As I mentioned in this post I should be able to run a script to find my current gateway’s MAC address. With this info, I should be able to tell when I am home, and launch a script. In this post, I talk about sleepwatcher, which runs a script when the machine is woken up. Sleepwatcher looks for a file named .wakerc and executes it when the machine wakes. If I put the following in my .wakerc, it will execute whatever I like (for example a rsync script) when the machine is woken up and at home:


sleep 120
GATEWAY=`/usr/sbin/netstat -rn | /usr/bin/grep default | /usr/bin/grep en1 | /usr/bin/cut -c20-35`
MACADDRESS=`/usr/sbin/arp -n $GATEWAY | /usr/bin/cut -f4 -d' '`
if [ "$MACADDRESS" = "xx:xx:xx:xx:xx:xx" ]; then
	/bin/echo "$(date): I am at home now: $MACADDRESS" >> ~/Desktop/wake.txt
	# script I want to run at home is next line
	rsync Documents/ server:Documents/
	/bin/echo "$(date): I don't know where I am: $GATEWAY $MACADDRESS" >> ~/Desktop/wake.txt

Running a BASH script when my Laptop is opened at home – Part 1

My laptop hard drive died. I was upset only because there was data on my laptop that had not been moved over to my desktop. My desktop has time machine and is rsynced to several other drives and locations.

So I lost data. My own fault because I was not diligent in moving data off my laptop.

To make sure this did not happen again, I needed the ability to run a script when I open my laptop at home. But how?

  • First, I thought about identifying being at home by my wireless SSID. That was okay, but what if I was connected by wire?
  • Second, I thought about identifying home based on my subnet. Well, I could find myself on a network with the same range, and that could be bad.
  • Then I found this link that showed some code on how to get the MAC address of the defined Default Gateway. Perfect.

MAC addresses should be unique. Therefore the BASH script should only run when I am on my home network.

Here is the BASH script to find the Default Gateway’s MAC address

GATEWAY=`netstat -rn | grep default | cut -c20-35`
MACADDRESS=`arp -n $GATEWAY | cut -f4 -d' '`

Next step is to use this code when I open my Laptop lid.

Using a MacBook to connect to a Cisco router

We have a “USBG-232MINI” USB to Serial adapter and I needed to connect to a Cisco router. GNU screen to the rescue!!

The command is

screen /dev/tty.usbserial-A9005yuF 9600 (Where A9005yuF is probably unique)

And to exit hit Control+A then K.

OS X: Move files based on creation date

I wanted to organize my flip videos – I wanted them moved into a folder named after their creation date.

One of the scripts that I found uses ls’s “–time-style” parameter. BSD’s ls does not have this value. MacPorts’ coreutils port contains gls (GNU’s ls) that does support the parameter. So here is my script to move movies into a sub folder based on the movies creation date.

for filename in *.MP4; do
    datepath="$(gls -l --time-style=+%Y-%m-%d $filename | awk '{print $6}')"
    echo "$datepath"
    if ! test -e "$datepath"; then
        mkdir -pv "$datepath"
    mv -v $filename $datepath

Powered by WordPress. Designed by WooThemes