Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 01-26-2004, 04:34 PM   #1
LQ Newbie
Registered: Jan 2004
Posts: 5

Rep: Reputation: 0
determining if shell is local connection or remote

How do I do it?

I want to make a prompt, among other things, that can tell if I'm on a local connection or connecting from a remote host.. First I was thinking about checking pts vs tty but that doesn't cut it. Maybe something about checking hosts in bashrc then setting a variable and the prompt. But how would I go about checking hosts like that?

Old 01-26-2004, 04:36 PM   #2
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
Welcome to LQ.

If it is an ssh connection then you should have the variables:
Old 01-26-2004, 04:40 PM   #3
LQ Newbie
Registered: Jan 2004
Posts: 5

Original Poster
Rep: Reputation: 0
Awesone.. Thanks for the quick reply.. Looks like I can test if $SSH_CONNECTION exists first then test it the first and third words of $SSH_CONNECTION are the same and that will give me local connection

Thanks agian,
Old 01-26-2004, 11:17 PM   #4
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
\h or \H will print out the host name.

If I change PS1 by the command: export PS1="\h@\H\$" I get the prompt:
jschiwal @ matrix.jesnet$

My default PS1 is set to "[\u@\h \W]\$". The host entry tells me where I'm logged in to.

The bash shell uses different startup files for a log-in session.
/etc/profile, then ~/.bash_profile, then ~/bash_login then ~/.profile. When logging out, bash reads and executes the commands in the file ~/.bash_logout.

When the shell is not a login session, ~/.bashrc is executed instead. The .bashrc file probably contains a test for /etc/profile, and executes it if it exists. But you could change this behaviour if you wanted to.

This is a little bit different from what you asked, but might give you an Idea which startup file should change PS1.

If you type: info bash and then PS1, you can find a listing of all of the prompt codes.

I think there is also a BASH PROMPT HowTo around with advice on what you might want in your prompt.

Last edited by jschiwal; 01-26-2004 at 11:41 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
setting-up an xserver connection with remote host through local firewall. schatoor Linux - Security 5 02-02-2006 10:11 AM
mounting local hard drive in a remote shell (SSH) noir911 Linux - General 1 06-24-2005 05:55 AM
determining shell abk4523 Linux - Newbie 2 06-09-2005 08:28 AM
Determining current shell subu_s Programming 11 01-04-2005 07:10 AM
Determining which shell is in use chakkerz Linux - Newbie 2 11-15-2004 05:47 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:07 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration