#! /usr/bin/expect
set command [lindex $argv 0]
set passwd [lindex $argv 1]
spawn su - root -c $command
expect "password:|口令:"
send $passwd\r
expect eof
exit


#! /usr/bin/expect
set passwd [ lindex $argv 0 ]
set shell_path [ lindex $argv 1 ]
spawn su - root
expect "口令:|Password:"
send $passwd\r
expect {
        "su*" {
                #expect eof
                #exit 24
                #send "echo password error\r"
                expect eof
                exit 10
        }
        "*#*" {
                #send "echo login succ\r"
                #expect eof
                #exit 11
  send "echo \r"
  send "$shell_path\r"
        }
}
expect eof
#exit


例子:
#! /usr/bin/expect
set uoa_passwd [ lindex $argv 0 ]
set uoa_ip [ lindex $argv 1 ]
set uoa_path [ lindex $argv 2 ]
spawn scp  ../bme_productconfig.xml uoa@$uoa_ip:$uoa_path/uoarun/data/templates
expect "?*"
send $uoa_passwd\r
expect eof

相关文章:

  • 2021-04-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-23
  • 2021-11-23
  • 2022-12-23
猜你喜欢
  • 2021-08-21
  • 2022-12-23
  • 2021-08-18
  • 2022-12-23
  • 2021-08-16
  • 2021-10-27
  • 2022-12-23
相关资源
相似解决方案