Get email upon change of IP address

Sometimes we just don’t have a fixed IP on a PC. Here is how to setup a cron script to email upon change (checked each hour). It uses the sendmail program to setup an email server on your PC.

sudo apt-get install sendmail
then type
> ~/.current_ip

then type
nano ~/scripts/checkIP
and cut and paste (change you@youremail to your email address)



IPADDRESS=$(hostname -I | tr -d [:space:])

if [[ ${IPADDRESS} != ${OldIP} ]]; then
echo "Your new IP address is ${IPADDRESS} (old address was ${OldIP} )" | mail -s "IP address change" $YOUREMAIL
echo ${IPADDRESS} > ~/.current_ip

4) chmod +x ~/scripts/checkIP

crontab -e
and then at the top add:


and at the bottom add:

0 * * * * ~/scripts/checkIP


7zipping and moving recursively by top-level directory

The following script takes the top-level directories and makes a 7zip archive from each top-level directory, containing all its subdirectories.

This function has a primitive “no-clobber” that won’t overwrite existing files.

Note that you can use up all HDD space if you have a lot of huge files — watch the progress of the program. You assume all risks for using this script.

# Michael Hirsch 2013
# BSD license
# 7zip's and moves files per directory

: ${2?example: 7z_mv ~/inDir /media/outDir}


#check if OutDir directory already exists
ArcOutDir=$OutDir/$MainDir #not for use inside tar command
if [ ! -d $ArcOutDir ]; then
echo creating $ArcOutDir
mkdir $ArcOutDir

#list ONLY 1st level subdirectories
DirList=($(find "$MainDir" -maxdepth 1 -mindepth 1 -type d | sort))
echo Found directories: ${DirList[@]}
nDir1=$(($nDir - 1))

#main loop
for i in $(seq 0 1 $nDir1); do

# no clobber
if [ -a $currArcOut ]; then
echo "Skipping directory $currDirIn since $currArcOut already exists"
continue #skips to top of for loop

echo "7zipping and moving $currDirIn to $currArcOut"

# don't use the -o option, it doesn't seem to work right
7za a -t7z -mx=3 -mmt=on -m0=lzma2 "$currArcOut" "$currDirIn"


Printing PDF from Matlab on Ubuntu

Sometimes you don’t have a color printer handy, and/or just want to print a color PDF for later reference — say a hand-annotated Matlab figure.
You need the CUPS PDF program, which saves printed PDFs to the ~/PDF directory.

sudo apt-get install cups-pdf

The output directory can be configured by editing the “Out” directory in:
sudo nano /etc/cups/cups-pdf.conf

Note, if you already have Matlab open, just restart Matlab to make the PDF printer available.

NOTE: Due to bug with Java, per Mathworks they say WONTFIX and here is a workaround that should always print in color (perhaps for Mac OS X and Windows as well)


and you’ll find the color test.pdf in your current directory. Phew!

Disable Beaglebone Black flashing heartbeat LED

To disable the annoying heartbeat LED:

sudo -s
echo none > /sys/class/leds/beaglebone\:green\:usr0/trigger

Note, this might reset at reboot.

You can search the web for how to make this permanent via the device tree (requires extraction and recompilation).

Might also be able to do something with rc.local — didn’t try this.


RTL2832 ADS-B decoder

the dump1090 program can be obtained by:

sudo apt-get install git libusb-1.0-0-dev cmake
git clone git://
mkdir ~/rtl-sdr/build
cd ~/rtl-sdr/build
sudo make install
sudo ldconfig

git clone
cd ~/dump1090

Then, do:


and look for the RTL2832 id codes similar to those below, and insert them in ATTRS(idvendor) and idProduct) if they’re different

sudo nano /etc/udev/rules.d/20.rtlsdr.rules

copy and paste this text

SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", GROUP="adm", MODE="0666", SYMLINK+="rtl_sdr"


sudo service udev restart

Now you can run the dump1090 ADS-B program by typing:

~/dump1090/dump1090 --interactive

Note: if you get a complaint about permissions, it’s easiest to just reboot your PC, which should fix the error.

WGET: download an HTTP or FTP directory recursively

Many science data sites are an Apache server with a HTTP index.html file listing, perhaps recursively, a lot of files and directories. You can download them recursively to your PC as follows (use this responsibly, you can consume gigabytes of data at cost to science host or yourself!)

wget -r -np -nc -nH --cut-dirs=4 --random-wait --wait 1 -e robots=off

This plops the files to whatever directory you ran the command in.

To use this on FTP site, just change the http:// to ftp:// and type the proper ftp site address.

Option explanation:
-r: download recursively (and place in recursive folders on your PC)
-np: Never get parent directories (sometimes a site will link back up and you don’t want that)
-nc: no clobber — don’t re-download files you already have
-nH: don’t put obnoxious site name directories on your PC
–cut-dirs=4: don’t put an obnoxious hierarchy of directories above the desired directory on your PC. Note you must set the number equal to the number of directories on server (here aaa/bbb/ccc/ddd is four)
-e robots=off: Many sites will block robots from mindlessly consuming huge amounts of data. Here we override this setting telling Apache that we’re (somewhat) human.
–random-wait: To avoid excessive download requests (that can get you auto-banned from downloading) we politely wait in-between files–better than trying to get yourself un-banned!
–wait 1: making the random wait time average to about 1 second before starting to download the next file.

Matlab missing libstdc++ error

if you get an error like:
/usr/local/MATLAB/R2013a/sys/os/glnxa64/ version `GLIBCXX_3.4.15′ not found (required by /usr/lib/

try doing:

cd /usr/local/MATLAB/R2013a_Student/sys/os/glnxa64
sudo mv
sudo ln -s /usr/lib/x86_64-linux-gnu/

Install Debian 7 to eMMC (internal flash drive) of Beaglebone Black

Note there’s now a semi-automated script to do this.

1) on your laptop PC, goto
and download the Debian 7 image (e.g. debian-wheezy-7.0.0-armhf-3.8.13-bone20.img.xz )
2) [optional] check that md5 sum is correct by typing in Terminal:
md5sum ~/Downloads/debian-wheezy-7.0.0-armhf-3.8.13-bone20.img.xz
this should match the md5 given at the download page
3) type lsblk, note which drives are listed, then insert the SD card into your laptop and type lsblk again–the new item is your SD card. Let’s say it was /dev/mmcblk0 (check on your PC!!)
4) type in Terminal:
sudo su
xz -cd debian-wheezy-7.0.0-armhf-3.8.13-bone20.img.xz > /dev/mmcblk0

5) This operation takes about 1-3 minutes — you’re writing data to the SD card at say 2MB/sec if using a Class 4 SD card, and say 6MB/sec if using a Class 10 SD card, and you’re writing uncompressed about 350 MB to the SD card. For fun, you can open another Terminal window and type sudo iotop or indicator-multiload to monitor the data writing.
6) insert this SD card into the (non-powered) BeagleBone Black and then apply the power.
7) Note, you might be one of those whose microHDMI adapter/monitor combo doesn’t work with the BBB. Well, it’s OK, since there is an SSH server running by default. You do need to know the IP address of the BBB on your LAN (plug the BBB into your Ethernet). Then, on your laptop Terminal, (assuming your IP addresses are like type:
nmap -v -sP | grep -B1 up
the BBB may show up as “debian-armhf”. Let’s say it’s
8) in Terminal on your laptop, type:
login: debian
password: debian

Change this password now by typing passwd at the

9) at the debian@debian-armhf:~$ prompt, type:
the line that looks like:
mmcblk1 179:8 0 1.8G 0 disk should be the internal BBB eMMC drive.
10) on your LAPTOP, type in Terminal:
scp ~/Downloads/debian-wheezy-7.0.0-armhf-3.8.13-bone20.img.xz debian@
11) At the BBB debian@debian-armhf:~$ prompt, type:
xz -cd debian-wheezy-7.0.0-armhf-3.8.13-bone20.img.xz > /dev/mmcblk1
12) after 3-5 minutes it will be done, type sudo poweroff and then remove SD card
13) power on after removing SD card and you’re on the internal eMMC

note, there are other ways to do this too.