一个基于zenity的linux远程连接客户端脚本(rdesktop/xfreerdp)


#!/bin/bash

#该脚本适用于CentOS与Ubuntu,其他系统可类似编写(该命令实现了USB、打印机以及语音的重定向,同时实现了本地机与远程机的互拷贝)

output=$(zenity --forms --title "" --text="信息" --separator="," --ok-label="确定" --cancel-label="取消" --add-entry="IP地址" --add-entry="端口号" --add-entry="域名" --add-entry="用户名" --add-password="密码")

if [ $? != 0 ];then
        exit 1
fi

path=$(cd `dirname $0`; pwd)
user=$(whoami)
ip=$(awk -F, '{print $1}' <<<$output)
domain=$(awk -F, '{print $3}' <<<$output)
port=$(awk -F, '{print $2}' <<<$output)
username=$(awk -F, '{print $4}' <<<$output)
password=$(awk -F, '{print $5}' <<<$output)
type1=$(cat /etc/redhat-release|awk '{print $1}')
type2=$(lsb_release -a|grep Distributor|awk '{print $3}')


#检测ip格式是否正确
checkIp(){
    if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
        FIELD1=$(echo $ip|cut -d. -f1)
        FIELD2=$(echo $ip|cut -d. -f2)
        FIELD3=$(echo $ip|cut -d. -f3)
        FIELD4=$(echo $ip|cut -d. -f4)
        if [ $FIELD1 -le 255 -a $FIELD2 -le 255 -a $FIELD3 -le 255 -a $FIELD4 -le 255 ]; then
            echo "IP $ip available."
        else
                zenity --error --title "错误" --text="IP格式不正确" --width="200" --height="40" --ok-label="确定"
                bash $path/client.sh
                exit 0
        fi
    else
                zenity --error --title "错误" --text="IP格式不正确" --width="200" --height="40" --ok-label="确定"
                bash $path/client.sh
                exit 0
    fi
}

#port格式
checkData(){
    [[ "$port" =~ ^[0-9]+$ ]] || zenity --error --title "错误" --text="端口格式不正确" --width="200" --height="40" --ok-label="确定"
    [[ "$port" =~ ^[0-9]+$ ]] || bash $path/client.sh
    [[ "$port" =~ ^[0-9]+$ ]] || exit 0
#用户名 密码
    if [ -z $username ];then
                zenity --error --title "错误" --text="用户名不能为空" --width="200" --height="40" --ok-label="确定"
                bash $path/client.sh
                exit 0
    elif [ -z $password ];then
                zenity --error --title "错误" --text="密码不能为空" --width="200" --height="40" --ok-label="确定"
                bash $path/client.sh
                exit 0
    fi
}

theCentOS(){   //centos系统执行的内容
     if [ -z $domain ];then
                 xfreerdp --no-nla -u $username -p $password --plugin rdpsnd --plugin cliprdr --plugin rdpdr --data printer --plugin rdpdr --data disk:${user}:/run/media/${user} -- ${ip}:${port}
                exit 0
        else
              xfreerdp --no-nla -u $username -p $password -d $domain --plugin rdpsnd --plugin cliprdr --plugin rdpdr --data printer --plugin rdpdr --data disk:${user}:/run/media/${user} -- ${ip}:${port}
               exit 0
        fi
}

theUbuntu(){   //ubuntu执行的内容
     if [ -z $domain ];then
                 rdesktop -u $username -p $password -r sound -r disk:USB=/media/${user} -r printer:mydeskjet -r clipboard:PRIMARYCLIPBOARD ${ip}:${port} &
                 exit 0
        else
                 rdesktop -u $username -p $password -d $domain -r sound -r disk:USB=/media/${user} -r printer:mydeskjet -r clipboard:PRIMARYCLIPBOARD ${ip}:${port} &
                exit 0
        fi
}

checkIp
checkData
if [[ $type1 = CentOS  || $type2 = CentOS ]];then
    theCentOS
else
    theUbuntu       
fi

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值