Chinaunix首页 | 论坛 | 博客
  • 博客访问: 677961
  • 博文数量: 467
  • 博客积分: 8050
  • 博客等级: 中将
  • 技术积分: 14825
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-18 11:00
文章分类

全部博文(467)

文章存档

2009年(8)

2008年(459)

分类: LINUX

2008-04-09 14:25:47

#!/bin/bash
#
# Author:
# CopyRight :
#

############### Begin #################

# User Function and Variables definition
LOCALFILE="${HOME}/ssh-management"
if [ ! -f $LOCALFILE ]
then
  touch $LOCALFILE
fi

[ -f /usr/bin/dialog ] || { echo "Not found dialog";exit 1; }
[ -f $LOCALFILE ] || touch $LOCALFILE

# User Program Main
function ADDSSH_HOST {
clear
echo -n "Pleast Input SSH Host IP: "
read -r ADDSSH[0]
DIGIT=(${ADDSSH[0]//[!0-9]/ })
[ "${#DIGIT[@]}" != "4" ] && {
        echo "IP ADDRESS ERROR "
        exit 1
}
echo -n "Pleast Input SSH Host Port (Default 22): "
read -r ADDSSH[1]
[ -z ${ADDSSH[1]} ] && ADDSSH[1]=22
if (( 0>${ADDSSH[1]} && ${ADDSSH[1]}>65536 ));then
        echo "Port Error."
        exit 1
fi
echo -n "请输入用户名 (Default root): "
read -r ADDSSH[2]
[ -z ${ADDSSH[2]} ] && ADDSSH[2]=root
echo -n "Pleast Input Host Aliasname: "
read -r ADDSSH[3]
[[ ${ADDSSH[0]} != 127.0.0.1 ]] && echo ${ADDSSH[@]} >>$LOCALFILE
return 5
}

i=0
while read LINE
  do
        var=(${LINE});((i++))
        CONNECTING[$i]="$i '${var[0]}~${var[3]}'"
  done <${LOCALFILE}
CONNECTING[0]="0 'ADD-SSH-HOST'"
#25,50,20 height of outer border,width,height of inner border

dialog \
        --backtitle "SSH Mangemet" \
        --menu "SSH Accounts ... " 25 50 20 \
        --output-fd 3 \
        ${CONNECTING[@]} \
        3>/dev/shm/ssh-connect-tmp
[[ $(cat /dev/shm/ssh-connect-tmp) == 0 ]] && ADDSSH_HOST
[ $? = 5 ] && exec ${0}
SSHVAR=($(cat -n $LOCALFILE|grep "^\ \+$(cat /dev/shm/ssh-connect-tmp)[^0-9]"))
if [[ $(cat /dev/shm/ssh-connect-tmp) > 0 ]];then
        ssh -l ${SSHVAR[3]} -p ${SSHVAR[2]} ${SSHVAR[1]}
fi
rm -f /dev/shm/ssh-connect-tmp
exit 0
#############END#####################

阅读(399) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~