shell脚本expect实现一键登录服务器并进入指定目录删除文件

#!/usr/bin/expect -f

spawn ssh [email protected].*
expect "*password*"
send "*qwe123\r"
expect "*#"
send "cd /home/data/test\r"
expect "*#"
send "rm ./*\r"
expect {
  "*是否*"  {send "y\r"}
  "*没有*"  {send "\r"}
}
interact

mac系统将后缀名改为.command成为双击可执行文件

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章