Date: Fri, 16 Feb 1996 03:02:40 -0800 (PST) From: Donald Burr <d_burr@ix.netcom.com> To: Nate Williams <nate@sri.MT.net> Cc: Terry Lambert <terry@lambert.org>, Jerry Kendall <jerry@border.com>, questions@FreeBSD.org Subject: Re: Telling if User PPP is up or down Message-ID: <Pine.BSF.3.91.960216024725.426B-200000@starfleet.gov> In-Reply-To: <199602152251.PAA01813@rocky.sri.MT.net>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --] On Thu, 15 Feb 1996, Nate Williams wrote: > The line may be taken, but the link may not be 'up' if there is no > demand for it. OK, try this one. The syntax is "portstat <port>" (e.g. "portstat cuaa0") Just "portstat" alone will use the first port in use (the first lockfile in /var/spool/lock) Donald Burr [d_burr@ix.netcom.com], PO Box 91212, Santa Barbara CA 93190-1212 TEL (805)564-1871 / FAX 564-2315 / WWW http://www.geopages.com/WallStreet/2072 PGP Public Key available by request (send e-mail) or on Public Key Servers. ** Uphold your right to privacy - Use PGP. ** [-- Attachment #2 --] #!/bin/sh LOCK=/var/spool/lock if [ -z "$1" ] then cd ${LOCK} /bin/ls LCK..* > /tmp/locks$$ 2>/dev/null if [ ! -s /tmp/locks$$ ] then echo No ports in use. exit 0 fi PORT=`cat /tmp/locks$$ | head -1 | sed 's/^LCK\.\.//'` echo Warning: using port ${PORT} else PORT=${1} if [ ! -c /dev/${PORT} ] then echo error: no such port ${PORT} exit 1 fi fi # if a lock file does not exist, then obviously the port is not in use. if [ ! -f ${LOCK}/LCK..${PORT} ] then PORTSTAT="not in use" else # If a lock file exists, but the pid does not exist, it is stale, ergo # it is not in use. # # The head/awk stuff is for those bizarro programs that store more than # the pid in the lockfile (e.g. minicom). PID=`cat ${LOCK}/LCK..${PORT} | head -1 | awk '{ print $1 }'` # save a copy of the process ps ax | awk '{ print $1 " " $5 }' | grep "${PID}" > /tmp/portstat$$ # if file is zero-length, it don't exist if [ ! -s /tmp/portstat$$ ] then PORTSTAT="not in use (stale lock exists)" else # pids exist, so probe them PROGRAM=`cat /tmp/portstat$$ | awk '{ print $2 }'` if echo ${PROGRAM} | grep -i ppp > /dev/null 2>&1 then PORTSTAT="in use by ppp" else PORTSTAT="in use by `cat /tmp/portstat$$ | awk \ '{ print $2 }'`" fi fi fi echo "Status of ${PORT}: ${PORTSTAT}" exit 0help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.91.960216024725.426B-200000>
