Skip to content

Instantly share code, notes, and snippets.

@shdennlin
Forked from fkztw/ptt_autologin.sh
Last active August 29, 2021 08:57
Show Gist options
  • Save shdennlin/1be3e6d34f93f620db85ed76d899fad5 to your computer and use it in GitHub Desktop.
Save shdennlin/1be3e6d34f93f620db85ed76d899fad5 to your computer and use it in GitHub Desktop.
A shell script to login PTT via ssh automatically.
#!/usr/bin/env expect
# Login into PTT via SSH.
# Combine crontab with this script so you don't forget to login PTT everyday.
# Preparation:
# Ubuntu: $ sudo apt install expect
# Usage: /bin/bash -c ${FILE_PATH_OF_THIS_SCRIPT}
# Example in crontab:
# ptt auto login, every day at 12:00 PM
# 0 12 * * * /bin/bash -c ${ABSOLUTE_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"
expect {
"請輸入代號" { send "$BBS_ID\r" ; exp_continue }
"請輸入您的密碼" { send "$BBS_PW\r" ; exp_continue }
"您想刪除其他重複登入的連線嗎" { send "N\r" ; exp_continue }
"您要刪除以上錯誤嘗試的記錄嗎" { send "N\r" ; exp_continue }
"密碼不對喔" { exit }
"裡沒有這個人啦" { exit }
"請勿頻繁登入以免造成系統過度負荷" { send "\r" ; exp_continue }
"請按任意鍵繼續" { send "\r" ; exp_continue }
"oodbye" { exit }
}
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment