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_failure
exit
}
password {
send_user expect_failure
exit
}
Password {
send ${RemoteRootPasswd}\r;
send_user expect_eof
expect {
incorrect {
send_user expect_failure
exit
}
eof
}
}
eof
}
}
passphrase {
send ${KeyPasswd}\r;
send_user expect_eof
expect {
\"does not exist\" {
send_user expect_failure
exit
}
passphrase{
send_user expect_failure
exit
}
Password {
send ${RemoteRootPasswd}\r;
send_user expect_eof
expect {
incorrect {
send_user expect_failure
exit
}
eof
}
}
eof
}
}
Password {
send ${RemoteRootPasswd}\r;
send_user expect_eof
expect {
incorrect {
send_user expect_failure
exit
}
eof
}
}
\"No route to host\" {
send_user expect_failure
exit
}
\"Invalid argument\" {
send_user expect_failure
exit
}
\"Connection refused\" {
send_user expect_failure
exit
}
\"does not exist\" {
send_user expect_failure
exit
} \"Connection timed out\" {
send_user expect_failure
exit
}
timeout {
send_user expect_failure
exit
}
eof
}
}
set timeout $TimeOut
switch $ {
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 $?`
05-02 23:24