Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2086068
  • 博文数量: 414
  • 博客积分: 10312
  • 博客等级: 上将
  • 技术积分: 4921
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-31 01:49
文章分类

全部博文(414)

文章存档

2011年(1)

2010年(29)

2009年(82)

2008年(301)

2007年(1)

分类:

2008-04-07 06:59:49

#!/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#####################

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