Skip to content

Instantly share code, notes, and snippets.

@fkztw
Created January 9, 2018 13:53
Show Gist options
  • Save fkztw/ad375e227ec0f1ba450915df65433473 to your computer and use it in GitHub Desktop.
Save fkztw/ad375e227ec0f1ba450915df65433473 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.
# 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 [email protected]
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
@uWayLu
Copy link

uWayLu commented Sep 3, 2020

# ...
# Usage: /bin/bash -c '${FILE_PATH_OF_THIS_SCRIPT} ${BBS_ID} ${BBS_PW}'
set BBS_ID [lindex $argv 0]
set BBS_PW [lindex $argv 1]
# ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment