博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
expect 交互 之shell执行命令操作
阅读量:4663 次
发布时间:2019-06-09

本文共 2530 字,大约阅读时间需要 8 分钟。

shell 执行命令操作

/usr/bin/expect -c "proc jiaohu {} {    send_user expect_start    expect {        password {            send ${RemotePasswd}\r;            send_user expect_eof            expect {                \"does not exist\" {
send_user expect_failureexit 10 } password {send_user expect_failureexit 5 } Password {send ${RemoteRootPasswd}\r;send_user expect_eofexpect { incorrect { send_user expect_failure exit 6 } eof } } eof } } passphrase { send ${KeyPasswd}\r; send_user expect_eof expect { \"does not exist\" {
send_user expect_failureexit 10 } passphrase{send_user expect_failureexit 7 } Password {send ${RemoteRootPasswd}\r;send_user expect_eofexpect { incorrect { send_user expect_failure exit 6 } eof} } eof } } Password { send ${RemoteRootPasswd}\r; send_user expect_eof expect { incorrect {send_user expect_failureexit 6 } eof } } \"No route to host\" {
send_user expect_failure exit 4 } \"Invalid argument\" {
send_user expect_failure exit 8 } \"Connection refused\" {
send_user expect_failure exit 9 } \"does not exist\" {
send_user expect_failure exit 10 } \"Connection timed out\" {
send_user expect_failure exit 11 } timeout { send_user expect_failure exit 3 } eof }}set timeout $TimeOutswitch $1 { Ssh_Cmd { spawn ssh -t -p $Port -o StrictHostKeyChecking=no $RemoteUser@$Ip /bin/su - root -c \\\"$Cmd\\\" jiaohu } Ssh_Script { spawn scp -P $Port -o StrictHostKeyChecking=no $ScriptPath $RemoteUser@$Ip:/tmp/${ScriptPath##*/}; jiaohu spawn ssh -t -p $Port -o StrictHostKeyChecking=no $RemoteUser@$Ip /bin/su - root -c \\\"/bin/sh /tmp/${ScriptPath##*/}\\\" ; jiaohu } Scp_File { spawn scp -P $Port -o StrictHostKeyChecking=no -r $ScpPath $RemoteUser@$Ip:${ScpRemotePath}; jiaohu }}"state=`echo $?`

 

转载于:https://www.cnblogs.com/sharesdk/p/8710066.html

你可能感兴趣的文章