expect实现交互su到root

Shell Liemer_Lius 1003℃ 0评论

有时候需要su到root, 每次输入密码如果嫌麻烦的话, 可以使用以下的方法, 实现自动交互:

expect -c "
spawn su -
expect \"*assword*\"
send \"my_passwd\r\"
interact
"

交互式sftp传包:

cd file_dir
expect -c "
spawn sftp -o StrictHostKeyChecking=no lius@localhost 
expect \"*assword*\"
send \"my_passwd\r\"
expect \"sftp> \"
send \"put \*\r\"
expect \"sftp> \"
send \"exit\r\"
interact
"

 

转载请注明:liutianfeng.com » expect实现交互su到root

喜欢 (1)

发表回复