Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1056559
  • 博文数量: 573
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 66
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-28 16:21
文章分类

全部博文(573)

文章存档

2018年(3)

2016年(48)

2015年(522)

分类: C/C++

2015-12-02 20:34:54


点击(此处)折叠或打开

  1. #!/usr/bin/expect -f
  2. set timeout 45
  3. set ip [lindex $argv 0]
  4. set port [lindex $argv 1]
  5. set usr [lindex $argv 2]
  6. set pwd [lindex $argv 3]
  7. set oldname [lindex $argv 4]
  8. set newname [lindex $argv 5]

  9. spawn sftp -oport=$port $usr@$ip
  10. expect {
  11.     #需要输入密码
  12.     "*assword:"
  13.     {
  14.         send "$pwd\r";
  15.         expect {
  16.             "sftp>"
  17.             {
  18.                 send "rename '$oldname' '$newname'\r";
  19.                 expect "sftp>";
  20.                 send "quit\r";
  21.             }
  22.             #密码错误直接退出
  23.             "*assword:"
  24.             {
  25.                 send "\03";
  26.             }
  27.         }
  28.     }
  29.     #不需要输入密码
  30.     "sftp>"
  31.     {
  32.         send "rename '$oldname' '$newname'\r";
  33.         expect "sftp>";
  34.         send "quit\r";
  35.     }
  36.     #port或usr或ip错
  37.     "Connection closed"
  38.     {
  39.     }
  40. }
  41. expect eof
  42. exit

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