LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 01-26-2004, 05:34 PM   #1
SaxyWeed
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?

Thanks,
Matt
 
Old 01-26-2004, 05:36 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Welcome to LQ.

If it is an ssh connection then you should have the variables:
SSH_CONNECTION
SSH_CLIENT
 
Old 01-26-2004, 05:40 PM   #3
SaxyWeed
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,
matt
 
Old 01-27-2004, 12:17 AM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
\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-27-2004 at 12:41 AM.
 
  


Reply


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 11:11 AM
mounting local hard drive in a remote shell (SSH) noir911 Linux - General 1 06-24-2005 06:55 AM
determining shell abk4523 Linux - Newbie 2 06-09-2005 09:28 AM
Determining current shell subu_s Programming 11 01-04-2005 08:10 AM
Determining which shell is in use chakkerz Linux - Newbie 2 11-15-2004 06:47 PM


All times are GMT -5. The time now is 02:44 AM.

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