[ale] local/remote terminal

Danny Cox danny at compgen.com
Thu Jul 13 13:10:29 EDT 2000


Ben,

On Thu, 13 Jul 2000, Ben Phillips wrote:
> What line can I put into a startup script (.bash_profile) that will check
> whether I'm connecting from a local or remote tty?

	In general, you can't tell.

	In particular, there are three possibilities:

	1) You're on the console.  Under Linux this will be
/dev/tty{1,2,3,...?}

	2) You're on a serial port.  This will be /dev/ttyS?? or,
depending on the multiport card, a variation on this theme.

	3) You're coming in via the network using ssh (rsh, telnet, etc).
This will be on /dev/pts/*.  Unfortunatly, this applies to xterm and
rxvt as well.

	So: use 'tty' to print the name of the terminal you're on, and
match against that.

--------------------------------------------------------------------------
case $(tty) in
	/dev/pts/*) echo 'Network connection';;
	/dev/pty*)  echo '(old) Network connection';;
	/dev/ttyS*) echo 'Serial line';;
	/dev/tty*)  echo 'Console';;
	*)	    echo 'Hmm.  How ARE you connected?';;
esac
--------------------------------------------------------------------------

Danny

--
To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.





More information about the Ale mailing list