#!/depot/path/expect -- # faxstat 1.0 # Description: Check fax status on fax.nist.gov # Author: Don Libes # # By default, faxstat only shows lines describing the actual queue. # Optional -v flag makes it verbose. Shows ftp dialogue and entire file. log_user 0 set verbose 0 set timeout 120 spawn ftp fax.nist.gov proc bomb {msg} { log_user 1 send_user "faxstat: $msg\n" send_user "Try again later.\n" exit } expect_after timeout {bomb "Timed out after $timeout seconds."} \ eof {bomb "Received unexpect eof from fax server."} set argc [llength $argv] for {set i 1} {$i<$argc} {incr i} { set arg [lindex $argv $i] case $arg in \ "-v" { log_user 1 set verbose 1 } default { send_user "Usage: faxstat\n" send_user " or: faxstat -v (verbose)\n" exit } } expect "220*Name*): " send "anonymous\r" expect "331*Password:" send "$env(USER) via Expect script\r" expect "230*ftp> " send "cd misc\r" expect "250*ftp> " send "get status.fax /tmp/status.fax\r" expect "226*received*ftp> " send "quit\r" expect eof wait timeout if $verbose { send_user "[exec cat /tmp/status.fax]\n" } else { log_user 1 send_user "[exec grep "queued for" /tmp/status.fax]\n" } exec rm /tmp/status.fax