Linux Training

Linux training for private, public & voluntary sector.

0793 572 8612

City LinUX sample scripts - msg_cnt


# $Id: msg_cnt,v 1.1 2015/03/30 10:29:31 fulford Exp $
# $Source: /src/merlin/usr/local/etc/RCS/msg_cnt,v $
# $Revision: 1.1 $
# Author C W Fulford.
# Copyright 2014 (c) C W Fulford.
# Licensed for public use under the LGPL, .
# For assistance contact fulford@fulford.net 0709 229 5385
########################################################################
#log_user 0    ;# hide interaction, i.e. do not display to stdout
  set timeout 12
  match_max 100000

  set srvr  [lindex $argv 0]
  set proto [lindex $argv 1]
  set user  [lindex $argv 2]
  set mbox  [lindex $argv 3]
  set pass  [lindex $argv 4]

  if { $proto == "ssl" } {
	set port 993
	spawn  openssl s_client -connect  $srvr:$port -crlf
  } else {
	set port 143
  	spawn telnet $srvr $port
  }
  expect {
    timeout {puts stderr "timeout while connecting to $srvr"; exit 1}
    "not open" {puts stderr "cannot connect" ;puts stout "-1";exit 1}
    "* OK"
  }
  send "a001 login $user $pass\r"
  expect {
    timeout {puts stderr "Timed out on login with $user"; exit 1}
    "a001 NO" {puts stderr "Bad login - $user"; exit 1}
    "a001 OK" {send "a002 examine $mbox\r"
  		expect { timeout {
				puts stderr "Timed out when examining $mbox"
			 	exit 1
				}
    			 "a002 NO" {
				puts stderr "Could not examine $mbox";
			 	exit 1
				}
    			 "a002 OK"
		}
  		send "a003 logout\r"
	}
  }
######################################################################
# This program is free software: you can redistribute it and or      #
# modify it under the terms of the Lesser GNU General Public License #
# as published by the Free Software Foundation, either version 3 of  #
# the License, or (at your option) any later version.                #
#                                                                    #
# This program is distributed in the hope that it will be useful,    #
# but WITHOUT ANY WARRANTY; without even the implied warranty of     #    
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      #
# GNU General Public License for more details.                       #
#                                                                    # 
# A copy of the Lesser GNU General Public License and the GNU        #
# General Public License is available at                             #
# <http://www.gnu.org/licenses/>.                                    #
######################################################################

The layout and associated style sheets for this page are taken from the World Wide Web Consortium and used here under the W3C software licence.