LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2273|回复: 15

求一脚本(实现自动输入用户名和密码的)

[复制链接]
发表于 2005-10-8 21:44:50 | 显示全部楼层 |阅读模式
[root@localhost]# xrgsu                                                        #回车
XRGSupplicant 1.0.1
RuiJie Network CopyRight 2004
Please input your user name:117945644                                 #输入用户名
Please input your password:                                                   #输入密码
Use DHCP,1-Use,0-UnUse(Default: 0):1                                  #选择获取IP方式
Use default auth parameter,0-Use 1-UnUse(Default: 0):0       #选择默认参数设置
这个是我上网认证的整个过程(用过实达的都了解)
每次都要输入用户名和密码
下面也要输入1和0
请问哪位兄弟可不可以用shell实现
把它都记住呢
谢谢
发表于 2005-10-8 21:49:27 | 显示全部楼层
想干坏事~不告诉你,想干坏事也要自己努力
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-10-8 22:14:07 | 显示全部楼层
兄弟好打击人噢
我想了好久了
就是不成呀
现在没有太多时间学shell
所以就请大家了
怎么是干坏事呢
仅仅是像WIN下面那样让它记住我的上网号和密码呀
回复 支持 反对

使用道具 举报

发表于 2005-10-9 00:46:29 | 显示全部楼层
没用过实达 :| 不过可以参考HERE文档的方法

  1. command<<EOF
  2. ...
  3. EOF
复制代码
回复 支持 反对

使用道具 举报

发表于 2005-10-9 01:53:02 | 显示全部楼层
If the input accepts STDIN, then HERE will do, but if not, you will need to use expect language.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-10-9 12:16:19 | 显示全部楼层
xrgsu<<117945644
117945644
会产生死循环

我想试试xrgsu | grep "lease input your user name:";echo 117945644;
但前面搜不到那个东东
而运行xrgsu后会有那个的
[root@localhost c]# xrgsu
XRGSupplicant 1.0.1
RuiJie Network CopyRight 2004
Please input your user name:

用ifconfig | grep eth0就能搜到结果
不知为何

版主意思要用其它语言吗
难道shell无法实现像这种交互方式的输入吗
惨!!!
回复 支持 反对

使用道具 举报

发表于 2005-10-9 14:11:13 | 显示全部楼层
Post by 白水
xrgsu<<117945644
117945644
会产生死循环

我想试试xrgsu | grep "lease input your user name:";echo 117945644;
但前面搜不到那个东东
而运行xrgsu后会有那个的
[root@localhost c]# xrgsu
XRGSupplicant 1.0.1
RuiJie Network CopyRight 2004
Please input your user name:

用ifconfig | grep eth0就能搜到结果
不知为何

版主意思要用其它语言吗
难道shell无法实现像这种交互方式的输入吗
惨!!!

我没有用过xrgsu, 但大多数这种情况都是程序只接受tty设备的输入,而不是STDIN,所以要用到expect来模拟终端。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-10-9 15:36:06 | 显示全部楼层
版主说的是
可是我要怎么来模拟呢
麻烦你搞个提示呀
谢谢
真的不懂噢
回复 支持 反对

使用道具 举报

发表于 2005-10-9 18:58:09 | 显示全部楼层
以下脚本因为没有这个环境未经检验,你可以测试一下看是否成,需要安装expect

  1. #!/usr/bin/expect
  2. #Program: autoxrgsu
  3. #Author: HM Li <HM_Li@ustc.edu>
  4. #Date: 05-10-09
  5. log_user 1
  6. spawn xrgsu
  7. expect "name"
  8. send "117945644\r"
  9. log_user 0
  10. expect "password"
  11. send "yourpasswd\r"
  12. log_user 1
  13. expect "DHCP"
  14. send "1\r"
  15. expect "UnUse"
  16. send "0\r"
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-10-9 19:21:16 | 显示全部楼层
谢谢楼上兄弟
好像不行
兄弟也在合肥呵
   [root@localhost]# rpm -qa expect
                               expect-5.43.0-1


[root@localhost c]# sh xrgsu
                                 xrgsu: line 20: log_user: command not found
                                 xrgsu: line 21: spawn: command not found
                                 couldn't read file "name": no such file or directory
                                 xrgsu: line 23: send: command not found
                                 xrgsu: line 24: log_user: command not found
                                 couldn't read file "password": no such file or directory
                                 xrgsu: line 26: send: command not found
                                 xrgsu: line 27: log_user: command not found
                                 couldn't read file "DHCP": no such file or directory
                                 xrgsu: line 29: send: command not found
                                 couldn't read file "UnUse": no such file or directory
                                 xrgsu: line 31: send: command not found
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表