Hack41.Enable Quick telnetSSH Connections from the Desktop


Hack 41. Enable Quick telnet/SSH Connections from the Desktop

Desktop launchers and a simple shell script make a great combo for quick telnet and SSH connections to remote systems.

Many of us work with a large number of servers and often have to log in and out of them. Using KDE or GNOME's Application Launcher applet and a simple shell script, you can create desktop shortcuts that enabled you to quickly connect to any host using a variety of protocols.

To do this, create a script called connect, make it executable, and put it in a directory that is located in your PATH. This script should look like the following:

 #!/bin/bash progname='basename $0' type="single" if [ "$progname" = "connect" ] ; then proto=$1 fqdn=$2 shift shift elif [ "$progname" = "ctelnet" ]; then proto="telnet" fqdn=$1 shift elif [ "$progname" = "cssh" ]; then proto="ssh" fqdn=$1 shift elif [ "$progname" = "mtelnet" ]; then proto="telnet" fqdn=$1 hosts=$* type="multi" elif [ "$progname" = "mssh" ]; then proto="ssh" fqdn=$1 hosts=$* type="multi" fi args=$* # # Uncomment the xterm command and comment out the following if/else/fi clause # if you just want to use xterms everywhere # # xterm +mb -sb -si -T "${proto}::${fqdn}" -n ${host} -bg black -fg yellow - e ${proto} ${fqdn} ${args} # # Change Konsole to gnome-console and specify correct options if KDE is not installed # if [ "$type" != "multi" ]; then konsole -T "${proto}::${fqdn}" --nomenubar --notoolbar ${extraargs} -e ${proto} ${fqdn} ${args} else multixterm -xc "$proto %n" $hosts fi 

After creating this script and making it executable, create symbolic links to this script called cssh, ctelnet, mssh, and mtelnet in that same directory. As you can see from the script, the protocol and commands that it uses are based on the way in which the script was called.

To use this script when you are using KDE, right-click on the desktop and select Create New File Link to Application. This displays a dialog like the one shown in Figure 4-2. Enter the name of the script that you want to execute and the host that you want to connect to, and save the link.

Figure 4-2. Creating a desktop launcher in KDE


To use this script when you are using GNOME, right-click on the desktop and select Create Launcher. This displays a dialog like the one shown in Figure 4-3. Enter the name of the script that you want to execute and the host that you want to connect to, and save the link.

Figure 4-3. Creating a desktop launcher in GNOME


Using either of these methods, you quickly create desktop shortcuts that allow you to initiate a connection to a remote system by clicking on the link on your desktopno fuss, no muss!

4.14.1. See Also

  • "Execute Commands Simultaneously on Multiple Servers" [Hack #29]

Lance Tost



Linux Server Hacks (Vol. 2)
BSD Sockets Programming from a Multi-Language Perspective (Programming Series)
ISBN: N/A
EAN: 2147483647
Year: 2003
Pages: 162
Authors: M. Tim Jones

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net