Skip to content

Instantly share code, notes, and snippets.

@shdennlin
Last active December 21, 2021 16:53
Show Gist options
  • Save shdennlin/08dd849f696435ef9f13c30dd5bd49b1 to your computer and use it in GitHub Desktop.
Save shdennlin/08dd849f696435ef9f13c30dd5bd49b1 to your computer and use it in GitHub Desktop.
Auto login PTT via SSH and hold
#!/usr/bin/expect -f
# Auto login PTT via SSH and hold
# Preparation:
# -- Ubuntu: $ sudo apt install expect
# Usage: /bin/bash -c ${FILE_PATH_OF_THIS_SCRIPT}
spawn ssh -oBatchMode=no -oStrictHostKeyChecking=no bbsu@ptt.cc
set BBS_ID "REPLACE_WITH_YOUR_ID"
set BBS_PW "REPLACE_WITH_YOUR_PASSOWRD"
set sleep_time 0.1
expect {
"請輸入代號" { send "$BBS_ID\r" ; sleep $sleep_time ; exp_continue }
"請輸入您的密碼" { send "$BBS_PW\r" ; sleep $sleep_time ; exp_continue }
"您想刪除其他重複登入的連線嗎" { send "N\r" ; sleep $sleep_time ; exp_continue }
"您要刪除以上錯誤嘗試的記錄嗎" { send "N\r" ; sleep $sleep_time ; exp_continue }
"大富翁" { send "q" ; sleep $sleep_time ; exp_continue }
"密碼不對喔" { exit }
"裡沒有這個人啦" { exit }
"請勿頻繁登入以免造成系統過度負荷" { send "\r" ; sleep 1 ; exp_continue }
"請按任意鍵繼續" { send "\r" ; sleep $sleep_time ; exp_continue }
"oodbye" { sleep $sleep_time }
}
interact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment