From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6372 invoked from network); 27 Nov 2005 21:35:29 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 27 Nov 2005 21:35:29 -0000 Received: (qmail 13090 invoked from network); 27 Nov 2005 21:35:22 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 27 Nov 2005 21:35:22 -0000 Received: (qmail 16227 invoked by alias); 27 Nov 2005 21:35:14 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9716 Received: (qmail 16104 invoked from network); 27 Nov 2005 21:35:14 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 27 Nov 2005 21:35:14 -0000 Received: (qmail 12079 invoked from network); 27 Nov 2005 21:35:13 -0000 Received: from s1tank.virtdom.com (216.240.101.50) by a.mx.sunsite.dk with SMTP; 27 Nov 2005 21:35:13 -0000 Received: (qmail 93202 invoked by uid 89); 27 Nov 2005 22:05:02 -0000 Received: from unknown (HELO venti) (brian@aljex.com@68.164.251.130) by s1tank.virtdom.com with SMTP; 27 Nov 2005 22:05:02 -0000 Message-ID: <002c01c5f39a$657f4580$3200640a@venti> From: "Brian K. White" To: References: <001201c5f395$e4e47020$3200640a@venti> Subject: Re: ZSH Local or Remote? Date: Sun, 27 Nov 2005 16:34:48 -0500 Organization: Aljex Software MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2670 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 ----- Original Message ----- From: "Brian K. White" To: "zsh-users" Sent: Sunday, November 27, 2005 4:02 PM Subject: Re: ZSH Local or Remote? > ------------------ > #!/bin/ksh > # > # amilocal - "Am I Local?" > # Detects if the user is connecting from inside or outside the local LAN. > # > # Requires "tellip" > # > # Brian K. White - brian@aljex.com - Aljex Software > > TTY=`tty` > LOGFILE=/var/log/WAN-LOGINS > LOGGING=false > VERBOSE=false > > for ARG in $@ ; do > case ${ARG} in > -l) LOGGING=true ;; > -v) VERBOSE=true ;; > esac > done > > case ${TTY} in > /dev/tty[1-9]|/dev/tty[012][0-9]) > ${VERBOSE} && echo "YES: TTY=`tty`" > exit 0 > ;; > *) > IP=`tellip` > ID=`id -un` > grep -q ${IP} /etc/LAN && { > ${VERBOSE} && echo "YES: IP=${IP}" > exit 0 > } || { > ${LOGGING} && echo "`date`\t${ID}\t${IP}" >>${LOGFILE} > ${VERBOSE} && echo "NO: IP=${IP}" > exit 1 > } > ;; > esac > -------------- And of course I had to clean up a couple nits I hadn't noticed since I havn't modified or even looked at this in years: * Stop running tty and id unecessarily. * Stop using TTY since it collides with builtins in ksh93 and zsh at least, and who knows, it might not be overwriteable in some shell. In zsh it's overwriteable but not exportable. And I don't want to try to just use it if it exists since in my case it happens to always exist but not in the same format as `tty` or most shells builtin $TTY. Because I set it in /etc/profile, but I strip off the /dev/ and leave the rest. (It's used in the users main menu display so that we can ask them what tty they are so that we can double-vision them (like ttysnoop but much fancier) for training and customer support. Poor choice of variable name on my part, yes, but made too long ago and frankly, works fine under every shell but zsh. Including ksh93 and bash which also have a built-in $TTY #!/bin/ksh # amilocal - "Am I Local?" # Detects if the user is connecting from inside or outside the local LAN. # # Requires "tellip" # # Brian K. White - brian@aljex.com - Aljex Software MYTTY=`tty` LOGFILE=/var/log/WAN-LOGINS LOGGING=false VERBOSE=false for ARG in $@ ; do case $ARG in -l) LOGGING=true ;; -v) VERBOSE=true ;; esac done case $MYTTY in /dev/tty[1-9]|/dev/tty[012][0-9]) $VERBOSE && echo "YES: TTY=$MYTTY" exit 0 ;; *) IP=`tellip` grep -q $IP /etc/LAN && { $VERBOSE && echo "YES: IP=$IP" exit 0 } || { $LOGGING && echo "`date`\t`id -un`\t$IP" >>$LOGFILE $VERBOSE && echo "NO: IP=$IP" exit 1 } ;; esac -- Brian K. White -- brian@aljex.com -- http://www.aljex.com/bkw/ +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++. filePro BBx Linux SCO FreeBSD #callahans Satriani Filk!