Skip to content

Instantly share code, notes, and snippets.

@bilxio
Created November 29, 2017 07:32
Show Gist options
  • Save bilxio/8b289cd4577f4fd4d025a44249419dc5 to your computer and use it in GitHub Desktop.
Save bilxio/8b289cd4577f4fd4d025a44249419dc5 to your computer and use it in GitHub Desktop.
使用 expect 自动登录 ssh,修复 WINCH 信号传递
#!/usr/bin/expect -f
# 捕获 WINCH 信号,并传递给 Spawned 出来的 Children,
# 这样 ssh 的 TTY 就能随着窗口 resize 而适应。
trap {
set rows [stty rows]
set cols [stty columns]
stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH
set user <username>
set host <REMOTE_IP>
set password <PASSWORD>
set timeout -1
spawn ssh $user@$host
expect "*assword:*"
send "$password\r"
interact
expect eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment