This is a text-only version of the following page on https://raymii.org: --- Title : SSHdialog Author : Remy van Elst Date : 26-10-2009 URL : https://raymii.org/s/software/SSHDialog.html Format : Markdown/HTML --- ![][1] I wrote a script which combines dialog, awk and bash to make a nifty ssh script. First of, copy this script to your pc:

Recently I removed all Google Ads from this site due to their invasive tracking, as well as Google Analytics. Please, if you found this content useful, consider a small donation using any of the options below:

I'm developing an open source monitoring app called Leaf Node Monitoring, for windows, linux & android. Go check it out!

Consider sponsoring me on Github. It means the world to me if you show your appreciation and you'll help pay the server costs.

You can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $100 credit for 60 days.

#### SSHdialog #!/bin/bash ### Copyright (c) 2010 Remy van Elst #Permission is hereby granted, free of charge, to any person obtaining a copy #of this software and associated documentation files (the "Software"), to deal #in the Software without restriction, including without limitation the rights #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #copies of the Software, and to permit persons to whom the Software is #furnished to do so, subject to the following conditions: # #The above copyright notice and this permission notice shall be included in #all copies or substantial portions of the Software. # #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN #THE SOFTWARE. VERSION="1.2 beta." TITLE="SSHdialog $VERSION" HOSTSFILE="~/hosts" if [ -e $HOSTSFILE ]; then awk 'NF > 0' $HOSTSFILE > /tmp/sshost.hosts && cat /tmp/sshost.hosts > $HOSTSFILE else echo "Host file does not exist, please create it" echo "Use the following format:" echo; echo "number,servername,user,url/ip,port" echo "Example:" echo "1,VPS1,-,vps1.example.com,2223" echo "2,VPS2,john,vps2.example.org,2222" echo "3,Company Webserver,www,10.0.0.210,22" echo "4,Router,root,192.168.1.1,22" echo; echo "If you want the current user to be used as the username then use a - (dash)." echo "Each value is separated by a , (comma), and make sure you don't have double numbers. If you have only the first number will work." echo "If the syntax is not correct the script will fail so please make sure there are no errors..." echo exit 1 fi WIDTH=50 HEIGHT=40 MENUSIZE=6 TEMPF=`TEMPF 2>/dev/null` || TEMPF=/tmp/sshost.$$ OLDIFS=$IFS WHICHSSH="`whoami`@${HOSTN[$SSHOST]}" DIALOG=${DIALOG=dialog} IFS=$'n' ALINES=($(awk 'BEGIN{FS=","} {print $1}' $HOSTSFILE | wc -l)) LINES=($(awk 'BEGIN{FS=","} {print $1, """ $2 """}' $HOSTSFILE)) NAMES=($(awk 'BEGIN{FS=","} {print $2}' $HOSTSFILE)) UNAME=($(awk 'BEGIN{FS=","} {print $3}' $HOSTSFILE)) HOSTN=($(awk 'BEGIN{FS=","} {print $4}' $HOSTSFILE)) HOSTP=($(awk 'BEGIN{FS=","} {print $5}' $HOSTSFILE)) # if [ $ALINES -gt 6 ]; then MENUSIZE=$ALINES; else MENUSIZE=6; fi MENUSIZE=$ALINES SMURF="$DIALOG --extra-button --extra-label "Edit Hosts" --cancel-label "Exit" --ok-label "Connect" --menu "$TITLE" $HEIGHT $WIDTH $MENUSIZE ${LINES[*]}" eval $SMURF 2> $TEMPF RHOST=$? KEUZE=`cat $TEMPF` SSHOST=$[$KEUZE - 1] if [ ${UNAME[$SSHOST]} == "-" ]; then UNAME2=`whoami` WHICHSSH="$UNAME2@${HOSTN[$SSHOST]}" else UNAME2=${UNAME[$SSHOST]} WHICHSSH="$UNAME2@${HOSTN[$SSHOST]}" fi clear case $RHOST in 0) echo "Connecting user $UNAME2 to ${HOSTN[$SSHOST]} on port ${HOSTP[$SSHOST]}." ssh $WHICHSSH -p ${HOSTP[$SSHOST]} echo "ssh terminated, byebye" echo "This script is made by Raymii from http://raymii.org" ;; 1) echo "You selected exit, we will quit" exit 0 ;; 3) nano $HOSTSFILE exec bash $0 exit 0 ;; 255) echo "You pressed ESC, we will exit."; exit 0 ;; esac rm -f $TEMPF exit 0 Now comes the hard part, creating your hosts file. The script wants it to be in the same directory as the script with the name `hosts`. This is the syntax: ID,Friendly name,username,host or ip,port 1,VPS 1,-,vps.example.org,22 2,VPS 2,www,vps.someserver.com,2222 3,Home Router,root,192.168.1.1,22 4,Homeserver,-,192.168.1.10,22 5,Work,ceo,my.work.com,22 If you want the current user to be used as the username then use a `-` (dash) as username. Please double check your comma's and your numbers, if something is wrong the script can give strange errors. [1]: https://raymii.org/s/inc/img/sshdialog.png [2]: https://www.digitalocean.com/?refcode=7435ae6b8212 --- License: All the text on this website is free as in freedom unless stated otherwise. This means you can use it in any way you want, you can copy it, change it the way you like and republish it, as long as you release the (modified) content under the same license to give others the same freedoms you've got and place my name and a link to this site with the article as source. This site uses Google Analytics for statistics and Google Adwords for advertisements. You are tracked and Google knows everything about you. Use an adblocker like ublock-origin if you don't want it. All the code on this website is licensed under the GNU GPL v3 license unless already licensed under a license which does not allows this form of licensing or if another license is stated on that page / in that software: This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Just to be clear, the information on this website is for meant for educational purposes and you use it at your own risk. I do not take responsibility if you screw something up. Use common sense, do not 'rm -rf /' as root for example. If you have any questions then do not hesitate to contact me. See https://raymii.org/s/static/About.html for details.