#!/usr/bin/expect -- # # Expect script for automating a login session at SK5BN. # # 1. Check for new messages and private mail. # 2. If any private mail, open a file named 'mailbox' and save the mail. # 3. If any new messages, open a file named 'msglist' and save the # message list to it, else end the session. # 4. Logout from the BBS, and launch 'vi' to select the messages to read. # 5. End the session if no messages selected, else login again, and read # selected messages to default log file. # 7. Logout, and launch 'vi' to read/edit the messages. proc get_sid {} { global timeout set timeout 30 expect { eof { send_user "Connection closed by BBS, exiting...\n"; exit } timeout { send_user "No response from BBS, exiting...\n"; exit } -re "\\\[FBB-.*]\r\n" { set timeout -1 } } } proc chk_newmsgs {} { global msgfrom msgto expect { -re "Nya meddelanden: (\[0-9]+) to (\[0-9]+)" { set msgfrom $expect_out(1,string) set msgto $expect_out(2,string) } } } proc get_msglist {} { global bbs_call send "~o msglist\r" send "l\r" expect "$bbs_call>\r\n" } proc select_msgs {} { if {! [file exists msglist]} { return 1 } if {[catch {exec grep -q ^\[0-9]\[0-9]\[0-9] msglist} errcode]} { send_user "No messages in list.\n"; return 1 } catch {system vi msglist} errcode if {[catch {system awk 'BEGIN \{printf \"r \"\; n = 0\} \ /^\\t/\{printf \"%d \", \$1\; n++\} \ END \{printf \"\\n\"\; if (n) exit 0\; else exit 1\}' \ msglist > readcmd } errcode ]} { return 1 } else { return 0 } } proc get_msgs {} { global bbs_call send "~o\r" send "~u readcmd\r" expect "$bbs_call>\r\n" } proc chk_mail {} { global bbs_call expect { "till dig." { expect "$bbs_call>\r\n" send "~o mailbox\r" send "rm\r" expect "$bbs_call>\r\n" send "~c\r" send "km\r" exp_continue } "$bbs_call>\r\n" } } proc logout {} { send "b\r" wait } set bbs_call "SK5BN" if {$argc == 0} { if [file exists msglist] { exec rm msglist } spawn -noecho call -r 144 sk5bn get_sid chk_newmsgs chk_mail if {$msgto == $msgfrom} { logout; exit } get_msglist logout } if {[select_msgs] == 0} { spawn -noecho call -r 144 sk5bn get_sid chk_mail get_msgs logout catch {system vi logfile.txt} errcode send_user "Remove file 'logfile.txt' (y/n)? " expect_user "y" { exec rm logfile.txt } "n" } .