SSH Escape

September 3rd, 2008

You can get into a special area of SSH that you by using the SSH Escape key sequence.

It can be set at the connection time to a custom character but if you didn’t set one it is probably set to the Tilda (~). To open the SSH Escape dialog to manage your connection (I assume you know what you want to do, but your wondering how you use it)

Its simple to use; just hit shift, then the back tick (`) to get the Tilda (~) then type the command you want to use.

For example to pull up the SSH Escape dialog help up you use the question mark (?) so do the following:

[owen@Linux_Blog ~]$ ~?
Supported escape sequences:
~. - terminate connection
~B - send a BREAK to the remote system
~C - open a command line
~R - Request rekey (SSH protocol 2 only)
~^Z - suspend ssh
~# - list forwarded connections
~& - background ssh (when waiting for connections to terminate)
~? - this message
~~ - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)

Are You Funding Open Source?

August 31st, 2008

I was using a piece of software that I had heard about a while back that manages collections. Its called Tellico and is actually quite good. While using Tellico I discovered that when you click on the “Amazon link” for the product, it has an affiliate code in it.

For those of you who don’t know what an affiliate program is, its basically a way for people to make money just by refering people to products. Most of the big guys have these sorts of “programs” including Amazon. Affiliate programs are very popular in the triple X industry.

What frustrates me is that this is included in Tellico, so in effect when you visit a product from your own personal collection, Tellico gets a percentage of sales from Amazon for any other items you purchase. While the affiliate link doesn’t bother me so much as it can be changed (and I also participate in the program), its the fact that it came right out of the Fedora repositories like this.

What about if Ubuntu reworked its software and included affiliate links for everything? Perhaps a FireFox plugin that manipulated all Amazon requests to include Mandriva’s affiliate link. I think that this is against Amazons terms of service but this method is a potential way for open source developers and organizations to get some additional funding. But is it right? Preying on your end users ignorance for profit? Although it doesn’t harm anything is it moral?

Reworking Shell Scripts

August 27th, 2008

To me shell Scripts are all about automation, their primary purpose is to get stuff done. If you have a one liner, snippet or other script you use on a regular basis, have you thought about how you could rework it for it to become more in handy?

Lets take last weeks snippet from this column. It was a simple one liner to reconnect to a host. Now, I knew when I posted this article that it was a helpful snippet of code. Now, how can this script be adapted to be a neat utility that we use on a regular basis? Over the next few week’s we’ll find out.

The first thing that I will note on is that this script or shell snippet is a pain to remember. Does a script save you time if you can’t remember how it works? Is it worth the hassle? Not exactly. So, in order to make this snippet a little better the first thing we are going to do is add something that it needs: parameters. Adding parameters to shell scripts is actually easy, much easier than adding parameters to some other languages that we wont mention. although this script does not use it getopts can be used. I’ve covered how to do this with getopts in other posts. Just do a site search (located at the bottom of the right bar for getopts.)

So, here is the modified script that automatically reconnects to a host by using ping and SSH:

#!/bin/bash

# Sleep Time Default: 15 seconds
STIME=15

# Set a default user up
USERNAME=LinuxBlog

#usage function
usage () {
echo -e “Usage: $0 host [user] [Sleep Time]”
}

# display usage if no host is specified
[ -z $1 ] && { usage && exit 1; }

# set the variables
[ $1 ] && { HOST=$1; }
[ $2 ] && { USERNAME=$2; }
[ $3 ] && { STIME=$3; }

# trying:
echo -e “host: $HOST \nuser: $USERNAME \ndelay: $STIME”

while ! ping -W 1 -c 1 $HOST 2>&1 >/dev/null; do true; done && echo “Successful waiting: $STIME secs”; sleep $STIME; ssh $USERNAME@$HOST

Now that you have that done, all you need to do is give the file a name (I called mine ssh_auto) and put it in a folder in your path. Use the filename and parameters defined in the script to connect to the host.

The next shell scripting article I demonstrate how you can further rework shell scripts to better suit your needs.

Before you complain / ask about Java

August 27th, 2008

Before you ask why your Java applications don’t work, or why your applet doesn’t initialize in Firefox, Seamonkey or Whatever browser you use do you know what version of Java you are using?

“Yes, I installed the JRE 1.6.0_XX”,

Thats nice, but is it running? Now, it may seem as obvious as “Is your computer on?”  to some, but to others and I admit myself it isn’t always that obvious. I had installed the Java Runtime /JDK and tested my firefox. Programs worked from the command line, java -version provided me the correct Java version, but why were my applets failing to load?

The firefox plugin is the answer. Open up about:plugins in firefox and take a look at the Java providers. If you don’t see the Java(TM) plugin there then there is a problem. Refer to the Correct Java documentation on how to get this corrected. Basically you symlink a file and disable the other Java providers.

Suspend Scripts for the Toshiba Tecra M2

August 21st, 2008

As you may know if you are a regular reader I own a
Toshiba Tecra M2. One of the things that annoyed me was I had to turn the
brightness up every time my computer came out of standby mode. A fix for this is
to adjust the brightness every time the computer comes out of standby mode.

The script is intended to be run under cron. I have mine set up to suspend
after 5 minutes of the lid being closed.

if [ $(cat /proc/acpi/button/lid/LID/state | sed ’s/state:      //’) ==
“closed” ]; then
VAR=$(cat /proc/acpi/toshiba/lcd | sed ’s/brightness:              //’ grep
-v levels);
sudo su -c “echo mem > /sys/power/state”;
if [ $VAR -eq 1 ]; then
ACTION=ADD;
elif [ $VAR -eq 7 ]; then
ACTION=SUB;
else
ACTION=ADD;
fi;
if [ $ACTION == “ADD” ]; then
VAR=$(($VAR + 1));
else
VAR=$(($VAR - 1));
fi;
sudo su -c “echo brightness:$(echo $VAR) > /proc/acpi/toshiba/lcd”;
fi;

I run this with the following cron entry:

*/5 * * * * sh hibernate.sh

The script first checks the current brightness. If the brightness is
currently 1 or 7 it adjusts the mathematic operation so that when the laptop is
opened the brightness is adjusted. Basically if the brightness is one, it adds
one. If the brightness is 7 or any other value it subtracts one. This is
currently working out quite well for me. I don’t know how useful this is to any
body else, unless you happen to have a Toshiba that is doing the same thing but
it should give you a good overall idea of how to perform basic mathematic
operations in bash.