Posts Tagged ‘terminal’

A good script.

A good script.

I just finished setting up something neat for my MacBook Pro: a script that takes the IP address of the laptop on wake and writes it to a file that is then synced online via Dropbox.

It starts with the set of terminal commands on scripts called SleepWatcher. This program looks for a file called .sleep and .wakeup int he users home directory and executes them upon sleep and wake respectively. They can contain any UNIX script from say “Goodnight Michael” to, well, grabbing the current IP.

The command used to get the current IP and write it to a file is:

curl http://myip.ozymo.com -o /Users/michaelhutchins/Documents/Dropbox/wan_ip_mac.txt

With the /michaelhutchins… part replaced with your username and where you want the file to go (and be called). To make the use TextEdit or anything to make a file called sleep.txt. Then rename this to .sleep saying yes to all the warning of hidden files and removing the .txt extension. My full script is the above with one added line:

sleep 5;

curl http://myip.ozymo.com -o /Users/michaelhutchins/Documents/Dropbox/wan_ip_mac.txt;

The sleep 5 just waits five seconds so the computer can make the connection to the internet. Once it was done in Terminal I typed chmod +x .wakeup to make it executable. With this and sleepwatcher installed it now updated the IP address whenever it wakes up.

Why is this useful? I see it as a security measure. If my laptop is ever lost or stolen I can use the IP to SSH in to maybe find out where it went or at least narrow down the options. I can also use Screen Sharing through OS X to see what is on the screen by connecting with the IP address. Or if the IP is for a coffee house or public place a well placed “say “I am stolen!” on repeat may help.

Also in the future I may see about setting my computer up as a file server I can wake remotely in case I need to get a file. Though I have yet to experiment with that.

Read Full Post »

GeekTools Commands

A nice way to decorate an underpass.

A nice way to decorate an underpass.

The other day I mentioned that I starting using GeekTools. When I first got it thought “Looks pretty cool” followed by “How do I do that?”. So here are the four commands I use (one is a bit more involved):

System Uptime (Refresh 240):

uptime | awk ‘{print “UPTIME : ” $3 ” “$4″ ” $5 “”}’

System Processes (Refresh 5):

top -ocpu -FR -l2 -n20 | grep ‘^….[1234567890] ‘ | grep -v ‘ 0.0% ..:’ | cut -c 1-24,33-42,64-77

Calender (Refresh 3600):

cal | sed “s/^/ /;s/$/ /;s/ $(date +%e) / $(date +%e | sed ‘s/./#/g’) /”

Current iTunes Song (Refresh 10):

osascript /Users/michaelhutchins/Music/iTunesInfo.scpt

This one just actively runs a scripts that I acquired (along with the originals) from this site of GeekTools programs and commands. The uptime I adjusted slightly while the others are pretty much the original.

I should mention that the refresh rates are in seconds even though it has no demarcation.

All of these are Shell scripts with everything at the default setting except font color, I chose white since it shows up better on my current background.

Read Full Post »