Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: ZSH Local or Remote?
- X-seq: zsh-users 9716
- From: "Brian K. White" <brian@xxxxxxxxx>
- To: <zsh-users@xxxxxxxxxx>
- Subject: Re: ZSH Local or Remote?
- Date: Sun, 27 Nov 2005 16:34:48 -0500
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: Aljex Software
- References: <E3336F7C-77CC-4670-8EE9-5911598B9B23@xxxxxxxxxxxxxxx> <001201c5f395$e4e47020$3200640a@venti>
----- Original Message -----
From: "Brian K. White" <brian@xxxxxxxxx>
To: "zsh-users" <zsh-users@xxxxxxxxxx>
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@xxxxxxxxx - 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@xxxxxxxxx - 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@xxxxxxxxx -- http://www.aljex.com/bkw/
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx Linux SCO FreeBSD #callahans Satriani Filk!
Messages sorted by:
Reverse Date,
Date,
Thread,
Author