shell报错 大牛解答一下
Tofloor
poster avatar
FEI17
deepin
2012-05-06 01:35
Author
shell内容
  1. #!/usr/bin/expect  
  2.     spawn sudo myxrgsu -d  
  3.     expect "passwd:"  
  4.     send "FEI17\r"   
  5.     expect "*name:"
  6.     send "2\r"
  7.     expect "password:"
  8.     send "2\r"
  9.     expect "parameter"
  10.     send "0\r"
  11.     exit
Copy the Code

执行结果 求解答
  1. aloof@linux-rewx:~> sh /home/aloof/桌面/连接锐捷.sh
  2. /home/aloof/桌面/连接锐捷.sh:行2: spawn: 未找到命令
  3. couldn't read file "passwd:": no such file or directory
  4. /home/aloof/桌面/连接锐捷.sh:行4: send: 未找到命令
  5. couldn't read file "*name:": no such file or directory
  6. /home/aloof/桌面/连接锐捷.sh:行6: send: 未找到命令
  7. couldn't read file "password:": no such file or directory
  8. /home/aloof/桌面/连接锐捷.sh:行8: send: 未找到命令
  9. couldn't read file "parameter": no such file or directory
  10. /home/aloof/桌面/连接锐捷.sh:行10: send: 未找到命令
  11. aloof@linux-rewx:~> sh /home/aloof/桌面/连接锐捷.sh
Copy the Code
Reply Favorite View the author
All Replies
woodelf
deepin
2012-05-06 02:06
#1
第一行为何是
  1. #!/usr/bin/expect
Copy the Code
Reply View the author
FEI17
deepin
2012-05-06 02:37
#2
第一行为何是
  1. #!/usr/bin/expect
Copy the Code

第一行是照这个网上抄来的
我估计是引用expect这个软件
Reply View the author
woodelf
deepin
2012-05-06 02:45
#3
[quote]第一行为何是
  1. #!/usr/bin/expect
Copy the Code

第一行是照这个网上抄来的
我估计是引用expect这个软件[/quote]
首行中的符号#!告诉系统其后路径所指定的程序,即是解释此脚本文件的Shell程序。一般都是/bin/sh或者/bin/bash,也可能是我孤陋寡闻了。
Reply View the author
FEI17
deepin
2012-05-06 03:13
#4
[quote][quote]第一行为何是
  1. #!/usr/bin/expect
Copy the Code

第一行是照这个网上抄来的
我估计是引用expect这个软件[/quote]
首行中的符号#!告诉系统其后路径所指定的程序,即是解释此脚本文件的Shell程序。一般都是/bin/sh或者/bin/bash,也可能是我孤陋寡闻了。[/quote]

我先用你的试试看吧
Reply View the author
FEI17
deepin
2012-05-06 03:18
#5
不行啊
Reply View the author
chenyinsen
deepin
2012-05-09 01:33
#6
sudo apt-get install expect
然后再跑这个脚本
Reply View the author
FEI17
deepin
2012-05-09 05:56
#7
sudo apt-get install expect
然后再跑这个脚本

我是suse

expect安装过了 问题是其他几个关键词报错
Reply View the author
chenyinsen
deepin
2012-05-09 23:54
#8
chmod +x /home/aloof/桌面/连接锐捷.sh
/home/aloof/桌面/连接锐捷.sh
看看结果
Reply View the author
lisonic
deepin
2012-05-13 08:29
#9
不知道楼主的问题解决了没有。
问题就出在第一句的注释上,#!/usr/bin/expect,这虽然是注释但是也指明了要使用的命令解释器及其路径。
楼主本来是要用myxrgsu进行认证的,但是它是个交互式的命令,比如要输入用户名、密码等。
这个脚本就是使用expect来封闭myxrgsu的,从而可以根据myxrgsu的输出自动地输入相关信息,
比如,要密码时( "passwd:" )输入 "FEI17",要用户名( "*name:")就输入 "2"。
前面的spawn sudo myxrgsu -d一句就是告诉expect要接管myxrgsu的输入输出的。
-------------------------------
从楼主给的错误信息可以明显地看出,命令解释器不能识别spawn和send等命令。
建议楼主先用which expect命令确认一个expect的路径,如果不在/usr/bin/expect路径的话,
相应地改一下再试。
Reply View the author