[comp.unix.questions] determining port id

george@wciu.wciu.edu (George Peavy) (03/20/91)

I'm still learning shell programming, and have hit a snag that, so far, I 
haven't been able to figure out.

Here's what's happening:  I'm writing a menu program that, among other things,
allows a user to select the option of up/downloading files to/from a PC.
Since I also have terminals attached, I want to disallow this option unless
the user is working from a port known to have a pc attached to it.

What I have so far:  I'm using Bourne shell on AT&T Sys V 3.0 running on a 
Unisys 6000/51 platform.  I can get the port id with,

	who am i | awk '{ print $2 }'

The question is, how do I get this information into a place where I can
test the value?  Is there a simpler way than my use of awk?

posted(and I hope I've gotten the right group for followup) and email
replies both welcomed.

Thanks in advance.
-- 
George Peavy

(george@wciu.edu)

jik@athena.mit.edu (Jonathan I. Kamens) (03/20/91)

  (Note: "Followup-To: comp.unix.questions, george@wciu.edu" is not valid for
two reasons.  The first is that there shouldn't be any spaces in it.  And the
second is that you can't put E-mail addresses in the Followup-To line.  You
must put either a list of newsgroups or the word "poster" to ask for E-mail
replies only.)

In article <1991Mar19.171708.18628@wciu.EDU>, george@wciu.wciu.edu (George Peavy) writes:
|> What I have so far:  I'm using Bourne shell on AT&T Sys V 3.0 running on a 
|> Unisys 6000/51 platform.  I can get the port id with,
|> 
|> 	who am i | awk '{ print $2 }'
|> 
|> The question is, how do I get this information into a place where I can
|> test the value?  Is there a simpler way than my use of awk?

  If you really want to use awk, then you can use backquotes to evaluate the
command above and assign its output to a variable, e.g.

	tty=`who am i | awk '{ print $2 }'`

However, it seems to me that the "tty" command will give you the same
information, and only requires one process:

	tty=`tty`

The output of tty will have "/dev/" at the front of it (assuming that your
devices are in /dev :-), but you can cope with that rather trivially.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710

rad@genco.bungi.com (Bob Daniel) (03/22/91)

In article <1991Mar19.171708.18628@wciu.EDU> george@wciu.wciu.edu (George Peavy) writes:
>
>What I have so far:  I'm using Bourne shell on AT&T Sys V 3.0 running on a 
>Unisys 6000/51 platform.  I can get the port id with,
>
>	who am i | awk '{ print $2 }'
>

This is how I do it...

device=`tty`
port=`basename $device`
echo $port


The "`" are accent marks, not single quotes.  I'm on AT&T SysV 3.2.3.
This is also more accurate than using 'who am i' when using 'layers'.

rad@genco.bungi.com (Bob Daniel) (03/22/91)

In article <1991Mar19.171708.18628@wciu.EDU> george@wciu.wciu.edu (George Peavy) writes:
>I'm still learning shell programming, and have hit a snag that, so far, I 
>haven't been able to figure out.
>
>Here's what's happening:  I'm writing a menu program that, among other things,
>allows a user to select the option of up/downloading files to/from a PC.
>Since I also have terminals attached, I want to disallow this option unless
>the user is working from a port known to have a pc attached to it.
>
>
>	who am i | awk '{ print $2 }'
>
>The question is, how do I get this information into a place where I can
>test the value?  Is there a simpler way than my use of awk?

This is how I do it...

device=`tty`
port=`basename $device`

if [ "$port" = "ttyXX" ]
then
 ...
fi

or instead of 'if'....

case $port in
	ttyX1) 	foo1;;
	ttyX2) 	foo2;;
	  etc)	fooX;;
esac

______
The ` is accent marks, not single quotations.  I'm using AT&T SysV 3.2.3 so
this should work for you.