Posts Tagged ‘ command line

Uploading images to imgur from the Linux/Mac command line

I have been using this for a few years and felt it worthwhile sharing. Add the following to your .profile, .bashrc, etc:

imgur(){
  for i in "$@";do
    curl -# -F "image"=@"$i" -F "key"="b822c1d8c517c03062a48a1181ec0cd2" http://api.imgur.com/2/upload.xml|\
    grep -Eo '<[a-z_]+>http[^<]+'|sed 's/^<.\|_./\U&/g;s/_/ /;s/<\(.*\)>/\x1B[0;34m\1:\x1B[0m /'
  done
}

Then, when you load a new shell, you should be able to do something like:

(0)(18:23:23)chuck@sepang:~$ imgur gmailcounts2.jpg 
######################################################################## 100.0%
Original: http://i.imgur.com/KEguAM4.jpg
Imgur Page: http://imgur.com/KEguAM4
Delete Page: http://imgur.com/delete/JJfaLyU8HYnAVrF
Small Square: http://i.imgur.com/KEguAM4s.jpg
Large Thumbnail: http://i.imgur.com/KEguAM4l.jpg

Securing Synergy

At work, I have several computers on my desk, but I prefer to only use one mouse and keyboard to control all of them. To accomplish this, I use Synergy. The more recent versions of Synergy come with the ability to perform encryption on the connections through Synergy itself, but I did not feel it adequate enough or easy enough to use for my needs. Instead, I run Synergy on my machine which has the keyboard and mouse attached to it, then on my client machines, I tunnel the remote server’s synergy port to the local machine, and connect locally, This tunnels all Synergy traffic through SSH transparently, and is extremely secure. I like this level of security because often times, I am typing personal, sensitive, or confidential information on one of the client machines using the server’s keyboard.

In my setup, cota.austin.ibm.com is the Synergy server. All SSH is done through public key encryption to make the connection painless.
Here is the script I use:

#!/bin/bash -x

function clean()
{
    for job in `ps -eo pid,args | grep ssh | grep 24800 | grep -v grep | awk '{print $1}'`
    do
        kill -9 $job
    done
}

trap clean SIGINT

ssh -f -N -L localhost:24800:cota.austin.ibm.com:24800 cemeyer@cota.austin.ibm.com
synergyc -f localhost
clean

I hope this helps someone else looking for an easy way to secure down Synergy.

Automapping channel numbers to TiVo commands from the Ubuntu command line

In a previous post, I described how to control your TiVo from the Linux command line. I wanted to take it a bit further and make it easier to enter numeric IR codes to my TiVo. With some pointers from Alex Lambert, I came up with a solution that works on my Ubuntu 12.04 laptop.

I am assuming you followed the instructions in the previous post and have created the following symlinks:

lrwxrwxrwx 1 chuck chuck   10 Dec  4 23:24 NUM0 -> tivoircode
lrwxrwxrwx 1 chuck chuck   10 Dec  4 23:24 NUM1 -> tivoircode
lrwxrwxrwx 1 chuck chuck   10 Dec  4 23:24 NUM2 -> tivoircode
lrwxrwxrwx 1 chuck chuck   10 Dec  4 23:24 NUM3 -> tivoircode
lrwxrwxrwx 1 chuck chuck   10 Dec  4 23:24 NUM4 -> tivoircode
lrwxrwxrwx 1 chuck chuck   10 Dec  4 23:24 NUM5 -> tivoircode
lrwxrwxrwx 1 chuck chuck   10 Dec  4 23:24 NUM6 -> tivoircode
lrwxrwxrwx 1 chuck chuck   10 Dec  4 23:24 NUM7 -> tivoircode
lrwxrwxrwx 1 chuck chuck   10 Dec  4 23:25 NUM8 -> tivoircode
lrwxrwxrwx 1 chuck chuck   10 Dec  4 23:25 NUM9 -> tivoircode
lrwxrwxrwx 1 chuck chuck   10 Dec  4 23:32 ENTER -> tivoircode

Now, the goal here is that simply entering the command such as “1695” will send the sequence NUM1;NUM6;NUM9;NUM5 to the TiVo. This can be accomplished using the same facility that Ubuntu uses to suggest packages to install when you issue a command from a package that is not currently installed. To do this, add the following to your ~/.bashrc:

function is_integer() {
    s=$(echo $1 | tr -d 0-9)
    if [ -z "$s" ]; then
        return 0
    else
        return 1
    fi
}

command_not_found_handle() {
        if is_integer $1; then
                for NUM in `echo $1 | fold -w1`
                do
                        NUM$NUM
                done
#               ENTER
        else
                if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
                if [ -x /usr/lib/command-not-found ]; then
                   /usr/bin/python /usr/lib/command-not-found -- "$1"
                   return $?
                elif [ -x /usr/share/command-not-found/command-not-found ]; then
                   /usr/bin/python /usr/share/command-not-found/command-not-found -- "$1"
                   return $?
                else
                   printf "%s: command not found\n" "$1" >&2
                   return 127
                fi
                fi

        fi
}

Now, when you enter an numeric integer value on your bash session, it will send it to your TiVo as a series of IR codes for each digit in the number. You can uncomment the final ENTER command if you wish for the enter button to be pressed when a number is finished being entered on the TiVo, but that is up to you. This function copies the body of the command_not_found_handle default function from /etc/bash.bashrc that ships with Ubuntu, so that non-integer commands are sent through the old mechanism and no functionality is lost.

Happy TiVo’ing